WEBVTT

NOTE Created by CaptionSync from Automatic Sync Technologies www.automaticsync.com

00:00:01.076 --> 00:00:03.996 align:middle
Do you remember the only rule for a controller?

00:00:04.756 --> 00:00:07.696 align:middle
It must return a Symfony Response object!

00:00:08.286 --> 00:00:14.386 align:middle
But Symfony doesn't care how you do that: you
could render a template, make API requests

00:00:14.516 --> 00:00:17.516 align:middle
or make database queries
and build a JSON response.

00:00:18.126 --> 00:00:24.826 align:middle
Really, most of learning Symfony involves
learning to install and use a bunch of powerful,

00:00:25.086 --> 00:00:28.596 align:middle
but optional, tools that make this work easier.

00:00:28.596 --> 00:00:34.566 align:middle
If your app needs to return HTML, then
one of these great tools is called Twig.

00:00:35.566 --> 00:00:40.556 align:middle
First, make sure you commit all of your
changes so far: I already did this.

00:00:41.066 --> 00:00:44.926 align:middle
Recipes are so much more fun
when you can see what they do!

00:00:46.436 --> 00:00:54.296 align:middle
Now run: composer require twig By the way, in
future tutorials, our app will become a mixture

00:00:54.296 --> 00:00:58.936 align:middle
of a traditional HTML app and an
API with a JavaScript front-end.

00:00:59.706 --> 00:01:02.976 align:middle
So if you want to know about building
an API in Symfony, we'll get there!

00:01:03.986 --> 00:01:08.356 align:middle
This installs TwigBundle, a
few other libraries and...

00:01:08.546 --> 00:01:10.546 align:middle
configures a recipe!

00:01:11.416 --> 00:01:12.786 align:middle
What did that recipe do?

00:01:13.596 --> 00:01:17.286 align:middle
Let's find out: git status Woh!

00:01:17.546 --> 00:01:19.026 align:middle
Lot's of good stuff!

00:01:20.046 --> 00:01:23.046 align:middle
The first change is config/bundles.php.

00:01:24.216 --> 00:01:26.956 align:middle
Bundles are the "plugin" system for Symfony.

00:01:27.526 --> 00:01:29.946 align:middle
And whenever we install a third-party bundle,

00:01:30.216 --> 00:01:33.676 align:middle
Flex adds it here so that
it's used automatically.

00:01:34.456 --> 00:01:35.346 align:middle
Thanks Flex!

00:01:36.746 --> 00:01:41.316 align:middle
The recipe also created some
stuff, like a templates/ directory!

00:01:42.066 --> 00:01:46.656 align:middle
Yep, no need to guess where
templates go: it's pretty obvious!

00:01:47.326 --> 00:01:50.486 align:middle
It even added a base layout
file that we'll use soon.

00:01:51.486 --> 00:01:58.416 align:middle
Twig also needs some configuration, so the
recipe added it in config/packages/twig.yaml.

00:01:59.106 --> 00:02:03.826 align:middle
But even though this file was added
by Flex, it's yours to modify:

00:02:04.926 --> 00:02:06.936 align:middle
you can make whatever changes you want.

00:02:07.446 --> 00:02:09.396 align:middle
Oh, and I love this!

00:02:09.826 --> 00:02:13.206 align:middle
Why do our templates need to
live in a templates/ directory.

00:02:13.636 --> 00:02:16.006 align:middle
Is that hardcoded deep inside Symfony?

00:02:16.816 --> 00:02:18.266 align:middle
Nope! It's right here!

00:02:19.136 --> 00:02:24.216 align:middle
Don't worry about this percent syntax yet -
you'll learn about that in a future episode.

00:02:24.676 --> 00:02:31.716 align:middle
But, you can probably guess what's going
on: %kernel.project_dir% is a variable

00:02:31.716 --> 00:02:33.586 align:middle
that points to the root of the project.

00:02:34.386 --> 00:02:38.616 align:middle
Anyways, looking at what a recipe
did is a great way to learn!

00:02:39.056 --> 00:02:44.576 align:middle
But the main lesson of Flex is this: install
a library and it takes care of the rest.

00:02:45.516 --> 00:02:47.486 align:middle
Now, let's go use Twig!

