Skip to content

Commit 9846d97

Browse files
committed
feature #5001 Best practices template names (WouterJ)
This PR was merged into the 2.3 branch. Discussion ---------- Best practices template names @javiereguiluz @weaverryan wanted your opinion on this. Commits ------- 2b65304 Use snake_case for template names
2 parents 24f773c + 2b65304 commit 9846d97

File tree

5 files changed

+66
-62
lines changed

5 files changed

+66
-62
lines changed

Diff for: best_practices/templates.rst

+4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ Another advantage is that centralizing your templates simplifies the work
5151
of your designers. They don't need to look for templates in lots of directories
5252
scattered through lots of bundles.
5353

54+
.. best-practice::
55+
56+
Use lowercased snake_case for directory and template names.
57+
5458
Twig Extensions
5559
---------------
5660

Diff for: book/controller.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -471,14 +471,14 @@ If you're serving HTML, you'll want to render a template. The ``render()``
471471
method renders a template **and** puts that content into a ``Response``
472472
object for you::
473473

474-
// renders app/Resources/views/Hello/index.html.twig
475-
return $this->render('Hello/index.html.twig', array('name' => $name));
474+
// renders app/Resources/views/hello/index.html.twig
475+
return $this->render('hello/index.html.twig', array('name' => $name));
476476

477477
You can also put templates in deeper sub-directories. Just try to avoid creating
478478
unnecessarily deep structures::
479479

480-
// renders app/Resources/views/Hello/Greetings/index.html.twig
481-
return $this->render('Hello/Greetings/index.html.twig', array('name' => $name));
480+
// renders app/Resources/views/hello/greetings/index.html.twig
481+
return $this->render('hello/greetings/index.html.twig', array('name' => $name));
482482

483483
The Symfony templating engine is explained in great detail in the
484484
:doc:`Templating </book/templating>` chapter.

Diff for: book/forms.rst

+20-20
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ from inside a controller::
9696
->add('save', 'submit', array('label' => 'Create Task'))
9797
->getForm();
9898

99-
return $this->render('Default/new.html.twig', array(
99+
return $this->render('default/new.html.twig', array(
100100
'form' => $form->createView(),
101101
));
102102
}
@@ -144,14 +144,14 @@ helper functions:
144144

145145
.. code-block:: html+jinja
146146

147-
{# app/Resources/views/Default/new.html.twig #}
147+
{# app/Resources/views/default/new.html.twig #}
148148
{{ form_start(form) }}
149149
{{ form_widget(form) }}
150150
{{ form_end(form) }}
151151

152152
.. code-block:: html+php
153153

154-
<!-- app/Resources/views/Default/new.html.php -->
154+
<!-- app/Resources/views/default/new.html.php -->
155155
<?php echo $view['form']->start($form) ?>
156156
<?php echo $view['form']->widget($form) ?>
157157
<?php echo $view['form']->end($form) ?>
@@ -442,12 +442,12 @@ corresponding errors printed out with the form.
442442

443443
.. code-block:: html+jinja
444444

445-
{# app/Resources/views/Default/new.html.twig #}
445+
{# app/Resources/views/default/new.html.twig #}
446446
{{ form(form, {'attr': {'novalidate': 'novalidate'}}) }}
447447

448448
.. code-block:: html+php
449449

450-
<!-- app/Resources/views/Default/new.html.php -->
450+
<!-- app/Resources/views/default/new.html.php -->
451451
<?php echo $view['form']->form($form, array(
452452
'attr' => array('novalidate' => 'novalidate'),
453453
)) ?>
@@ -784,7 +784,7 @@ of code. Of course, you'll usually need much more flexibility when rendering:
784784

785785
.. code-block:: html+jinja
786786

787-
{# app/Resources/views/Default/new.html.twig #}
787+
{# app/Resources/views/default/new.html.twig #}
788788
{{ form_start(form) }}
789789
{{ form_errors(form) }}
790790

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

795795
.. code-block:: html+php
796796

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

@@ -1002,12 +1002,12 @@ to the ``form()`` or the ``form_start()`` helper:
10021002

10031003
.. code-block:: html+jinja
10041004

1005-
{# app/Resources/views/Default/new.html.twig #}
1005+
{# app/Resources/views/default/new.html.twig #}
10061006
{{ form_start(form, {'action': path('target_route'), 'method': 'GET'}) }}
10071007

10081008
.. code-block:: html+php
10091009

1010-
<!-- app/Resources/views/Default/newAction.html.php -->
1010+
<!-- app/Resources/views/default/newAction.html.php -->
10111011
<?php echo $view['form']->start($form, array(
10121012
'action' => $view['router']->generate('target_route'),
10131013
'method' => 'GET',
@@ -1437,7 +1437,7 @@ do this, create a new template file that will store the new markup:
14371437

14381438
.. code-block:: html+jinja
14391439

1440-
{# app/Resources/views/Form/fields.html.twig #}
1440+
{# app/Resources/views/form/fields.html.twig #}
14411441
{% block form_row %}
14421442
{% spaceless %}
14431443
<div class="form_row">
@@ -1450,7 +1450,7 @@ do this, create a new template file that will store the new markup:
14501450

14511451
.. code-block:: html+php
14521452

1453-
<!-- app/Resources/views/Form/form_row.html.php -->
1453+
<!-- app/Resources/views/form/form_row.html.php -->
14541454
<div class="form_row">
14551455
<?php echo $view['form']->label($form, $label) ?>
14561456
<?php echo $view['form']->errors($form) ?>
@@ -1466,19 +1466,19 @@ renders the form:
14661466

14671467
.. code-block:: html+jinja
14681468

1469-
{# app/Resources/views/Default/new.html.twig #}
1470-
{% form_theme form 'Form/fields.html.twig' %}
1469+
{# app/Resources/views/default/new.html.twig #}
1470+
{% form_theme form 'form/fields.html.twig' %}
14711471

1472-
{% form_theme form 'Form/fields.html.twig' 'Form/fields2.html.twig' %}
1472+
{% form_theme form 'form/fields.html.twig' 'Form/fields2.html.twig' %}
14731473

14741474
{# ... render the form #}
14751475

14761476
.. code-block:: html+php
14771477

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

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

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

@@ -1606,7 +1606,7 @@ file:
16061606
twig:
16071607
form:
16081608
resources:
1609-
- 'Form/fields.html.twig'
1609+
- 'form/fields.html.twig'
16101610
# ...
16111611
16121612
.. code-block:: xml
@@ -1621,7 +1621,7 @@ file:
16211621
16221622
<twig:config>
16231623
<twig:form>
1624-
<twig:resource>Form/fields.html.twig</twig:resource>
1624+
<twig:resource>form/fields.html.twig</twig:resource>
16251625
</twig:form>
16261626
<!-- ... -->
16271627
</twig:config>
@@ -1633,7 +1633,7 @@ file:
16331633
$container->loadFromExtension('twig', array(
16341634
'form' => array(
16351635
'resources' => array(
1636-
'Form/fields.html.twig',
1636+
'form/fields.html.twig',
16371637
),
16381638
),
16391639
// ...

Diff for: book/from_flat_php_to_symfony2.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ for example, the list template written in Twig:
710710

711711
.. code-block:: html+jinja
712712

713-
{# app/Resources/views/Blog/list.html.twig #}
713+
{# app/Resources/views/blog/list.html.twig #}
714714
{% extends "layout.html.twig" %}
715715

716716
{% block title %}List of Posts{% endblock %}

0 commit comments

Comments
 (0)