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
Use Twig templating format for your templates.
Generally speaking, PHP templates are 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).
Template Locations¶
Best Practice
Store the application templates in the templates/
directory at the root
of your project.
Centralizing your templates in a single location simplifies the work of your
designers. In addition, using this directory simplifies the notation used when
referring to templates (e.g. $this->render('admin/post/show.html.twig')
instead of $this->render('@SomeTwigNamespace/Admin/Posts/show.html.twig')
).
Best Practice
Use lowercased snake_case for directory and template names.