Templates

When PHP was created 20 years ago, developers loved its simplicity and how
well it blended HTML and dynamic code. But as time passed, other template
languages - like Twig - were created to make templating even better.

Best Practice

Best Practice

Use Twig templating format for your templates.

Generally speaking, PHP templates are much more verbose than Twig templates because
they lack native support for lots of modern features needed by templates,
like inheritance, automatic escaping and named arguments for filters and
functions.

Twig is the default templating format in Symfony and has the largest community
support of all non-PHP template engines (it's used in high profile projects
such as Drupal 8).

In addition, Twig is the only template format with guaranteed support in Symfony
3.0. As a matter of fact, PHP may be removed from the officially supported
template engines.

Traditionally, Symfony developers stored the application templates in the
Resources/views/ directory of each bundle. Then they used the Twig namespaced
path to refer to them (e.g. @AcmeDemo/Default/index.html.twig).

But for the templates used in your application, it's much more convenient
to store them in the app/Resources/views/ directory. For starters, this
drastically simplifies their logical names:

Templates Stored inside Bundles

Templates Stored in app/

@AcmeDemo/index.html.twig

index.html.twig

@AcmeDemo/Default/index.html.twig

default/index.html.twig

@AcmeDemo/Default/subdir/index.html.twig

default/subdir/index.html.twig

Another advantage is that centralizing your templates simplifies the work
of your designers. They don't need to look for templates in lots of directories
scattered through lots of bundles.