WEBVTT

NOTE Created by CaptionSync from Automatic Sync Technologies www.automaticsync.com

00:00:01.086 --> 00:00:05.066 align:middle
We just installed a new package by
running composer require templates.

00:00:05.336 --> 00:00:10.746 align:middle
Normally when you do that, Composer
will update the composer.json

00:00:10.806 --> 00:00:14.046 align:middle
and composer.lock files, but nothing else.

00:00:14.276 --> 00:00:19.436 align:middle
But when we run: git status
There are other changes.

00:00:19.816 --> 00:00:22.346 align:middle
This is thanks to Flex's recipe system.

00:00:23.156 --> 00:00:27.956 align:middle
Each time we install a new package,
Flex checks a central repository

00:00:28.266 --> 00:00:30.966 align:middle
to see if that package has a recipe.

00:00:31.386 --> 00:00:34.106 align:middle
And if it does, it installs it.

00:00:34.816 --> 00:00:36.836 align:middle
Where do these recipes live?

00:00:37.646 --> 00:00:39.506 align:middle
In the cloud...

00:00:39.816 --> 00:00:41.756 align:middle
or more specifically GitHub.

00:00:42.206 --> 00:00:42.836 align:middle
Check it out.

00:00:43.076 --> 00:00:49.256 align:middle
Run: composer recipes This is a
command added to composer by Flex.

00:00:50.036 --> 00:00:53.036 align:middle
It lists all of the recipes
that have been installed.

00:00:53.036 --> 00:01:00.786 align:middle
And if you want more info about one, just run:
composer recipes symfony/twig-bundle This is one

00:01:00.786 --> 00:01:03.066 align:middle
of the recipes that was just executed.

00:01:03.726 --> 00:01:04.896 align:middle
And... cool!

00:01:05.616 --> 00:01:07.596 align:middle
It shows us a couple of nice things!

00:01:08.496 --> 00:01:12.436 align:middle
The first is a tree of the
files it added to our project.

00:01:13.276 --> 00:01:16.996 align:middle
The second is a URL to the
recipe that was installed.

00:01:17.266 --> 00:01:19.206 align:middle
I'll click to open that.

00:01:20.476 --> 00:01:26.366 align:middle
Yep! Symfony recipes live in a special
repository called symfony/recipes.

00:01:27.216 --> 00:01:31.106 align:middle
This is a big directory organized
by package name.

00:01:31.946 --> 00:01:36.936 align:middle
There's a symfony directory that holds recipes
for all packages starting with symfony/.

00:01:37.086 --> 00:01:40.246 align:middle
The one we were just looking at...

00:01:40.666 --> 00:01:43.726 align:middle
is way down here: twig-bundle.

00:01:44.126 --> 00:01:49.876 align:middle
And then there are different versions of the
recipe based on your version of the package.

00:01:50.276 --> 00:01:53.296 align:middle
We're using the latest 5.4 version.

00:01:54.416 --> 00:01:59.326 align:middle
Every recipe has a manifest.json
file, which controls what it does.

00:02:00.186 --> 00:02:06.446 align:middle
The recipe system can only do a specific set
of operations, including adding new files

00:02:06.446 --> 00:02:10.596 align:middle
to your project and modifying
a few specific files.

00:02:10.666 --> 00:02:19.036 align:middle
For example, this bundles section tells flex to
add this line to our config/bundles.php file.

00:02:20.676 --> 00:02:24.186 align:middle
If we run git status again...

00:02:24.316 --> 00:02:26.366 align:middle
yup! That file was modified.

00:02:27.416 --> 00:02:35.616 align:middle
If we diff it: It added two lines,
probably one for each of the two recipes.

00:02:36.446 --> 00:02:42.086 align:middle
By the way, config/bundles.php is not a
file that you need to think about much.

00:02:42.556 --> 00:02:46.996 align:middle
A bundle, in Symfony land,
is basically a plugin.

00:02:46.996 --> 00:02:52.826 align:middle
So if you install a new bundle into your
app, that gives you new Symfony features.

00:02:53.436 --> 00:02:58.116 align:middle
In order to activate that bundle,
its name needs to live in this file.

00:02:58.236 --> 00:03:04.066 align:middle
So the first thing that the recipe did for
twig-bundle, thanks to this line up here,

00:03:04.396 --> 00:03:08.686 align:middle
was to activate itself inside bundles.php...

00:03:08.686 --> 00:03:11.456 align:middle
so that we didn't need to do it manually.

00:03:12.216 --> 00:03:14.906 align:middle
Recipes are like automated installation.

00:03:15.816 --> 00:03:20.126 align:middle
The second section in the manifest
is called copy-from-recipe.

00:03:20.586 --> 00:03:25.446 align:middle
This is simple: it says to copy the
config/ and templates/ directories

00:03:25.446 --> 00:03:27.906 align:middle
from the recipe into the project.

00:03:28.776 --> 00:03:29.796 align:middle
If we look...

00:03:30.386 --> 00:03:34.456 align:middle
the recipe contains a config/packages/twig.yaml
file...

00:03:35.026 --> 00:03:39.146 align:middle
and also a templates/base.html.twig file.

00:03:40.106 --> 00:03:42.586 align:middle
Back at the terminal, run git status again.

00:03:43.646 --> 00:03:48.646 align:middle
We see these two files at the
bottom: config/packages/twig.yaml...

00:03:49.136 --> 00:03:52.796 align:middle
and inside of templates/, base.html.twig.

00:03:53.506 --> 00:03:54.936 align:middle
I love this.

00:03:55.256 --> 00:03:58.926 align:middle
Think about it: if you install
a templating tool into your app,

00:03:59.286 --> 00:04:05.896 align:middle
we're going to need some configuration somewhere
that tells that templating tool which directory

00:04:05.896 --> 00:04:09.266 align:middle
to look inside of to find our templates.

00:04:09.266 --> 00:04:13.866 align:middle
Whelp, go check out that
config/packages/twig.yaml file.

00:04:14.806 --> 00:04:18.746 align:middle
We're going talk about these Yaml
files more in the next tutorial.

00:04:18.916 --> 00:04:26.186 align:middle
But on a high level, this file controls how Twig
- the templating engine for Symfony - behaves.

00:04:26.846 --> 00:04:32.956 align:middle
And check out the default_path key
set to %kernel.project_dir%/templates.

00:04:33.536 --> 00:04:39.426 align:middle
Don't worry about this percent syntax: that's a
fancy way to refer to the root of our project.

00:04:40.306 --> 00:04:43.626 align:middle
The point is, this config says: Hey Twig!

00:04:44.006 --> 00:04:48.326 align:middle
When you look for templates, look
for them in the templates/ directory.

00:04:48.516 --> 00:04:53.726 align:middle
And then the recipe even created that
directory with a layout file inside.

00:04:54.446 --> 00:04:57.166 align:middle
We'll use this in a few minutes.

00:04:57.236 --> 00:05:02.236 align:middle
The last unexplained file that
was modified is symfony.lock.

00:05:02.606 --> 00:05:07.826 align:middle
This is not important: it just keeps track
of which recipes have been installed...

00:05:07.826 --> 00:05:09.186 align:middle
and you should commit it.

00:05:09.846 --> 00:05:12.216 align:middle
In fact, we should commit all of this stuff.

00:05:12.606 --> 00:05:18.576 align:middle
The recipe might give us files,
but then they are our's to modify.

00:05:18.576 --> 00:05:19.596 align:middle
Run: git add .

00:05:20.216 --> 00:05:23.976 align:middle
Then: git status Cool.

00:05:24.296 --> 00:05:25.296 align:middle
Let's commit!

00:05:25.846 --> 00:05:31.526 align:middle
git commit -m "Adding Twig and
its beautiful recipe" Done!

00:05:32.286 --> 00:05:37.026 align:middle
By the way, a few months down the
road, there might be changes to some

00:05:37.026 --> 00:05:38.766 align:middle
of the recipes that you've installed.

00:05:39.106 --> 00:05:43.846 align:middle
And if there are, when you run
composer recipes you'll see a little

00:05:44.066 --> 00:05:45.956 align:middle
"update available" next to them.

00:05:46.746 --> 00:05:51.456 align:middle
Run composer recipes:update to
upgrade to the latest version.

00:05:52.436 --> 00:05:56.876 align:middle
Oh, and before I forget, in
addition to symfony/recipes,

00:05:57.176 --> 00:06:02.076 align:middle
there is also a symfony/recipes-contrib
repository.

00:06:02.586 --> 00:06:05.876 align:middle
So recipes can live in either
of these two places.

00:06:06.816 --> 00:06:11.536 align:middle
The recipes in symfony/recipes are
approved by Symfony's core team,

00:06:11.796 --> 00:06:14.576 align:middle
so they're a bit more vetted for quality.

00:06:15.086 --> 00:06:16.956 align:middle
Other than that, there's no difference.

00:06:17.976 --> 00:06:22.826 align:middle
Now, the recipe system is so
powerful that every single file

00:06:22.826 --> 00:06:25.946 align:middle
in our project was added via a recipe!

00:06:26.446 --> 00:06:27.116 align:middle
I can prove it.

00:06:27.116 --> 00:06:30.916 align:middle
Go to https://github.com/symfony/skeleton.

00:06:32.106 --> 00:06:36.386 align:middle
When we originally ran that symfony
new command to start our project,

00:06:36.936 --> 00:06:40.846 align:middle
what that really did was
clone this repository...

00:06:40.956 --> 00:06:43.606 align:middle
and then ran composer install inside of it,

00:06:43.876 --> 00:06:46.756 align:middle
which downloads everything
into the vendor/ directory.

00:06:47.356 --> 00:06:51.056 align:middle
Yup! Our project - the one
that we see right here -

00:06:51.366 --> 00:06:55.976 align:middle
was originally just a single
file: composer.json.

00:06:56.626 --> 00:06:59.196 align:middle
But then, when the packages were installed,

00:06:59.476 --> 00:07:04.326 align:middle
the recipes for those packages
added everything else we see.

00:07:05.536 --> 00:07:07.146 align:middle
Run: composer recipes again.

00:07:08.596 --> 00:07:11.916 align:middle
One recipe is for something
called symfony/console.

00:07:12.306 --> 00:07:18.776 align:middle
Check out its details: composer
recipes symfony/console And...

00:07:18.976 --> 00:07:25.226 align:middle
yes! The recipe for symfony/console
added the bin/console file!

00:07:26.116 --> 00:07:30.876 align:middle
The recipe for symfony/framework-bundle
- one of the other packages

00:07:30.876 --> 00:07:34.796 align:middle
that was originally installed
- added almost everything else,

00:07:35.146 --> 00:07:38.936 align:middle
including the public/index.php file.

00:07:39.306 --> 00:07:40.596 align:middle
How cool is that?

00:07:41.716 --> 00:07:44.356 align:middle
Okay next: we installed Twig!

00:07:44.746 --> 00:07:48.026 align:middle
So let's get back to work and
use it to render some templates!

00:07:48.396 --> 00:07:50.126 align:middle
You're going to love Twig.

