Skip to content

Commit

Permalink
Use snake_case for template names
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterj committed Jan 17, 2015
1 parent 5d74a67 commit 6825fee
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 66 deletions.
4 changes: 4 additions & 0 deletions best_practices/templates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------------

Expand Down
8 changes: 4 additions & 4 deletions book/controller.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 </book/templating>` chapter.
Expand Down
40 changes: 20 additions & 20 deletions book/forms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
));
}
Expand Down Expand Up @@ -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

<!-- app/Resources/views/Default/new.html.php -->
<!-- app/Resources/views/default/new.html.php -->
<?php echo $view['form']->start($form) ?>
<?php echo $view['form']->widget($form) ?>
<?php echo $view['form']->end($form) ?>
Expand Down Expand Up @@ -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

<!-- app/Resources/views/Default/new.html.php -->
<!-- app/Resources/views/default/new.html.php -->
<?php echo $view['form']->form($form, array(
'attr' => array('novalidate' => 'novalidate'),
)) ?>
Expand Down Expand Up @@ -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) }}

Expand All @@ -794,7 +794,7 @@ of code. Of course, you'll usually need much more flexibility when rendering:

.. code-block:: html+php

<!-- app/Resources/views/Default/newAction.html.php -->
<!-- app/Resources/views/default/newAction.html.php -->
<?php echo $view['form']->start($form) ?>
<?php echo $view['form']->errors($form) ?>

Expand Down Expand Up @@ -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

<!-- app/Resources/views/Default/newAction.html.php -->
<!-- app/Resources/views/default/newAction.html.php -->
<?php echo $view['form']->start($form, array(
'action' => $view['router']->generate('target_route'),
'method' => 'GET',
Expand Down Expand Up @@ -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 %}
<div class="form_row">
Expand All @@ -1450,7 +1450,7 @@ do this, create a new template file that will store the new markup:

.. code-block:: html+php

<!-- app/Resources/views/Form/form_row.html.php -->
<!-- app/Resources/views/form/form_row.html.php -->
<div class="form_row">
<?php echo $view['form']->label($form, $label) ?>
<?php echo $view['form']->errors($form) ?>
Expand All @@ -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

<!-- app/Resources/views/Default/new.html.php -->
<?php $view['form']->setTheme($form, array('Form')) ?>
<!-- app/Resources/views/default/new.html.php -->
<?php $view['form']->setTheme($form, array('form')) ?>

<?php $view['form']->setTheme($form, array('Form', 'Form2')) ?>
<?php $view['form']->setTheme($form, array('form', 'form2')) ?>

<!-- ... render the form -->

Expand Down Expand Up @@ -1606,7 +1606,7 @@ file:
twig:
form:
resources:
- 'Form/fields.html.twig'
- 'form/fields.html.twig'
# ...
.. code-block:: xml
Expand All @@ -1621,7 +1621,7 @@ file:
<twig:config>
<twig:form>
<twig:resource>Form/fields.html.twig</twig:resource>
<twig:resource>form/fields.html.twig</twig:resource>
</twig:form>
<!-- ... -->
</twig:config>
Expand All @@ -1633,7 +1633,7 @@ file:
$container->loadFromExtension('twig', array(
'form' => array(
'resources' => array(
'Form/fields.html.twig',
'form/fields.html.twig',
),
),
// ...
Expand Down
2 changes: 1 addition & 1 deletion book/from_flat_php_to_symfony2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down
2 changes: 1 addition & 1 deletion book/http_cache.rst
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ exposing a simple and efficient pattern::
$comments = ...;

// or render a template with the $response you've already started
return $this->render('Article/show.html.twig', array(
return $this->render('article/show.html.twig', array(
'article' => $article,
'comments' => $comments
), $response);
Expand Down
Loading

0 comments on commit 6825fee

Please sign in to comment.