diff --git a/best_practices/templates.rst b/best_practices/templates.rst index 801646587b2..7e96b2d5bfb 100644 --- a/best_practices/templates.rst +++ b/best_practices/templates.rst @@ -51,6 +51,10 @@ 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. +.. best-practice:: + + Use lowercased snake_case for directory and template names. + Twig Extensions --------------- diff --git a/book/controller.rst b/book/controller.rst index 52b6823e2b8..7fac4fe81aa 100644 --- a/book/controller.rst +++ b/book/controller.rst @@ -471,14 +471,14 @@ If you're serving HTML, you'll want to render a template. The ``render()`` method renders a template **and** puts that content into a ``Response`` object for you:: - // renders app/Resources/views/Hello/index.html.twig - return $this->render('Hello/index.html.twig', array('name' => $name)); + // renders app/Resources/views/hello/index.html.twig + return $this->render('hello/index.html.twig', array('name' => $name)); You can also put templates in deeper sub-directories. Just try to avoid creating unnecessarily deep structures:: - // renders app/Resources/views/Hello/Greetings/index.html.twig - return $this->render('Hello/Greetings/index.html.twig', array('name' => $name)); + // renders app/Resources/views/hello/greetings/index.html.twig + return $this->render('hello/greetings/index.html.twig', array('name' => $name)); The Symfony templating engine is explained in great detail in the :doc:`Templating ` chapter. diff --git a/book/forms.rst b/book/forms.rst index c6c366ce3c6..f4130ba696b 100644 --- a/book/forms.rst +++ b/book/forms.rst @@ -96,7 +96,7 @@ from inside a controller:: ->add('save', 'submit', array('label' => 'Create Task')) ->getForm(); - return $this->render('Default/new.html.twig', array( + return $this->render('default/new.html.twig', array( 'form' => $form->createView(), )); } @@ -144,14 +144,14 @@ helper functions: .. code-block:: html+jinja - {# app/Resources/views/Default/new.html.twig #} + {# app/Resources/views/default/new.html.twig #} {{ form_start(form) }} {{ form_widget(form) }} {{ form_end(form) }} .. code-block:: html+php - + start($form) ?> widget($form) ?> end($form) ?> @@ -442,12 +442,12 @@ corresponding errors printed out with the form. .. code-block:: html+jinja - {# app/Resources/views/Default/new.html.twig #} + {# app/Resources/views/default/new.html.twig #} {{ form(form, {'attr': {'novalidate': 'novalidate'}}) }} .. code-block:: html+php - + form($form, array( 'attr' => array('novalidate' => 'novalidate'), )) ?> @@ -784,7 +784,7 @@ of code. Of course, you'll usually need much more flexibility when rendering: .. code-block:: html+jinja - {# app/Resources/views/Default/new.html.twig #} + {# app/Resources/views/default/new.html.twig #} {{ form_start(form) }} {{ form_errors(form) }} @@ -794,7 +794,7 @@ of code. Of course, you'll usually need much more flexibility when rendering: .. code-block:: html+php - + start($form) ?> errors($form) ?> @@ -1002,12 +1002,12 @@ to the ``form()`` or the ``form_start()`` helper: .. code-block:: html+jinja - {# app/Resources/views/Default/new.html.twig #} + {# app/Resources/views/default/new.html.twig #} {{ form_start(form, {'action': path('target_route'), 'method': 'GET'}) }} .. code-block:: html+php - + start($form, array( 'action' => $view['router']->generate('target_route'), 'method' => 'GET', @@ -1437,7 +1437,7 @@ do this, create a new template file that will store the new markup: .. code-block:: html+jinja - {# app/Resources/views/Form/fields.html.twig #} + {# app/Resources/views/form/fields.html.twig #} {% block form_row %} {% spaceless %}
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: