From 2b65304a53fc4689c0cd48ce96c9359c6052deb4 Mon Sep 17 00:00:00 2001 From: WouterJ Date: Sat, 17 Jan 2015 01:23:27 +0100 Subject: [PATCH] Use snake_case for template names Conflicts: book/http_cache.rst book/validation.rst --- best_practices/templates.rst | 4 ++ book/controller.rst | 8 ++-- book/forms.rst | 40 ++++++++-------- book/from_flat_php_to_symfony2.rst | 2 +- book/templating.rst | 74 +++++++++++++++--------------- 5 files changed, 66 insertions(+), 62 deletions(-) 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 %}
@@ -1450,7 +1450,7 @@ do this, create a new template file that will store the new markup: .. code-block:: html+php - +
label($form, $label) ?> errors($form) ?> @@ -1466,19 +1466,19 @@ renders the form: .. code-block:: html+jinja - {# app/Resources/views/Default/new.html.twig #} - {% form_theme form 'Form/fields.html.twig' %} + {# app/Resources/views/default/new.html.twig #} + {% form_theme form 'form/fields.html.twig' %} - {% form_theme form 'Form/fields.html.twig' 'Form/fields2.html.twig' %} + {% form_theme form 'form/fields.html.twig' 'Form/fields2.html.twig' %} {# ... render the form #} .. code-block:: html+php - - setTheme($form, array('Form')) ?> + + setTheme($form, array('form')) ?> - setTheme($form, array('Form', 'Form2')) ?> + setTheme($form, array('form', 'form2')) ?> @@ -1606,7 +1606,7 @@ file: twig: form: resources: - - 'Form/fields.html.twig' + - 'form/fields.html.twig' # ... .. code-block:: xml @@ -1621,7 +1621,7 @@ file: - Form/fields.html.twig + form/fields.html.twig @@ -1633,7 +1633,7 @@ file: $container->loadFromExtension('twig', array( 'form' => array( 'resources' => array( - 'Form/fields.html.twig', + 'form/fields.html.twig', ), ), // ... diff --git a/book/from_flat_php_to_symfony2.rst b/book/from_flat_php_to_symfony2.rst index ff779b0dd14..147ecb0abd0 100644 --- a/book/from_flat_php_to_symfony2.rst +++ b/book/from_flat_php_to_symfony2.rst @@ -710,7 +710,7 @@ for example, the list template written in Twig: .. code-block:: html+jinja - {# app/Resources/views/Blog/list.html.twig #} + {# app/Resources/views/blog/list.html.twig #} {% extends "layout.html.twig" %} {% block title %}List of Posts{% endblock %} diff --git a/book/templating.rst b/book/templating.rst index b185e909017..95dedb298fc 100644 --- a/book/templating.rst +++ b/book/templating.rst @@ -263,7 +263,7 @@ A child template might look like this: .. code-block:: html+jinja - {# app/Resources/views/Blog/index.html.twig #} + {# app/Resources/views/blog/index.html.twig #} {% extends 'base.html.twig' %} {% block title %}My cool blog posts{% endblock %} @@ -277,7 +277,7 @@ A child template might look like this: .. code-block:: html+php - + extend('base.html.php') ?> set('title', 'My cool blog posts') ?> @@ -399,8 +399,8 @@ Most of the templates you'll use live in the ``app/Resources/views/`` directory. The path you'll use will be relative to this directory. For example, to render/extend ``app/Resources/views/base.html.twig``, you'll use the ``base.html.twig`` path and to render/extend -``app/Resources/views/Blog/index.html.twig``, you'll use the -``Blog/index.html.twig`` path. +``app/Resources/views/blog/index.html.twig``, you'll use the +``blog/index.html.twig`` path. .. _template-referencing-in-bundle: @@ -453,9 +453,9 @@ Every template name also has two extensions that specify the *format* and ======================== ====== ====== Filename Format Engine ======================== ====== ====== -``Blog/index.html.twig`` HTML Twig -``Blog/index.html.php`` HTML PHP -``Blog/index.css.twig`` CSS Twig +``blog/index.html.twig`` HTML Twig +``blog/index.html.php`` HTML PHP +``blog/index.css.twig`` CSS Twig ======================== ====== ====== By default, any Symfony template can be written in either Twig or PHP, and @@ -518,7 +518,7 @@ template. First, create the template that you'll need to reuse. .. code-block:: html+jinja - {# app/Resources/views/Article/articleDetails.html.twig #} + {# app/Resources/views/article/article_details.html.twig #}

{{ article.title }}

@@ -528,7 +528,7 @@ template. First, create the template that you'll need to reuse. .. code-block:: html+php - +

getTitle() ?>

@@ -542,20 +542,20 @@ Including this template from any other template is simple: .. code-block:: html+jinja - {# app/Resources/views/Article/list.html.twig #} + {# app/Resources/views/article/list.html.twig #} {% extends 'layout.html.twig' %} {% block body %}

Recent Articles

{% for article in articles %} - {{ include('Article/articleDetails.html.twig', { 'article': article }) }} + {{ include('article/article_details.html.twig', { 'article': article }) }} {% endfor %} {% endblock %} .. code-block:: html+php - + extend('layout.html.php') ?> start('body') ?> @@ -563,17 +563,17 @@ Including this template from any other template is simple: render( - 'Article/articleDetails.html.php', + 'Article/article_details.html.php', array('article' => $article) ) ?> stop() ?> The template is included using the ``{{ include() }}`` function. Notice that the -template name follows the same typical convention. The ``articleDetails.html.twig`` +template name follows the same typical convention. The ``article_details.html.twig`` template uses an ``article`` variable, which we pass to it. In this case, you could avoid doing this entirely, as all of the variables available in -``list.html.twig`` are also available in ``articleDetails.html.twig`` (unless +``list.html.twig`` are also available in ``article_details.html.twig`` (unless you set `with_context`_ to false). .. tip:: @@ -617,7 +617,7 @@ articles:: $articles = ...; return $this->render( - 'Article/recentList.html.twig', + 'article/recent_list.html.twig', array('articles' => $articles) ); } @@ -629,7 +629,7 @@ The ``recentList`` template is perfectly straightforward: .. code-block:: html+jinja - {# app/Resources/views/Article/recentList.html.twig #} + {# app/Resources/views/article/recent_list.html.twig #} {% for article in articles %} {{ article.title }} @@ -638,7 +638,7 @@ The ``recentList`` template is perfectly straightforward: .. code-block:: html+php - + getTitle() ?> @@ -812,7 +812,7 @@ any global default template that is defined): .. code-block:: jinja {{ render_hinclude(controller('...'), { - 'default': 'Default/content.html.twig' + 'default': 'default/content.html.twig' }) }} .. code-block:: php @@ -821,7 +821,7 @@ any global default template that is defined): new ControllerReference('...'), array( 'renderer' => 'hinclude', - 'default' => 'Default/content.html.twig', + 'default' => 'default/content.html.twig', ) ) ?> @@ -957,7 +957,7 @@ correctly: .. code-block:: html+jinja - {# app/Resources/views/Article/recentList.html.twig #} + {# app/Resources/views/article/recent_list.html.twig #} {% for article in articles %} {{ article.title }} @@ -966,7 +966,7 @@ correctly: .. code-block:: html+php - + getRequestFormat(); - return $this->render('Blog/index.'.$format.'.twig'); + return $this->render('article/index.'.$format.'.twig'); } The ``getRequestFormat`` on the ``Request`` object defaults to ``html``, @@ -1612,7 +1612,7 @@ their use is not mandatory. The ``Response`` object returned by a controller can be created with or without the use of a template:: // creates a Response object whose content is the rendered template - $response = $this->render('Article/index.html.twig'); + $response = $this->render('article/index.html.twig'); // creates a Response object whose content is simple text $response = new Response('response content'); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy