8000 Update most important book articles to follow the best practices by wouterj · Pull Request #4427 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

Update most important book articles to follow the best practices #4427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Nov 7, 2014
Merged
Prev Previous commit
Next Next commit
Proofread templating
  • Loading branch information
wouterj committed Nov 7, 2014
commit 9678b61cdf3dc14cf1f5995e2bd6352774a11414
32 changes: 16 additions & 16 deletions book/templating.rst
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,21 @@ By default, templates can live in two different locations:

* ``path/to/bundle/Resources/views/``: Each third party bundle houses its
templates in its ``Resources/views`` directory (and subdirectories). When you
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resources/views --> Resources/views/

plan to share your bundle, you should put the templates in the shared bundle
instead of the ``app/Resources/views`` directory.
plan to share your bundle, you should put the templates in the bundle instead
of the ``app/`` directory.

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.

Referencing Templates in a Bundle
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Symfony uses a **bundle**:**directory**:**filename** string syntax for
templates. You can also give paths, which are relative to the
``app/Resources/views`` directory. This allows for several different types of
templates that live inside a bundle. This allows for several different types of
templates, each which lives in a specific location:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also decided to tackle this naming discussion :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this section definitely needs updating! Maybe even more than we have already. I want to highlight the simple syntax first - basically say "most templates live in app/Resources/views, so just say their filename relative to that dir". THEN we have the discussion, "what if you want to put your templates in your bundle or need to reference a template from a third-party-bundle? Well, for that situation, we have this other syntax...".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great suggestion!


* ``AcmeBlogBundle:Blog:index.html.twig``: This syntax is used to specify a
Expand All @@ -419,24 +428,15 @@ templates, each which lives in a specific location:
Yes, there are 2 colons in the middle of the string when the "controller"
subdirectory part is missing.

* ``::base.html.twig``: This syntax refers to views in ``app/Resources/views``.
Notice that the string begins with two colons (``::``), meaning that both the
*bundle* and *directory* portions are missing. This means that the template
is not located in any bundle, but instead in the root
``app/Resources/views/`` directory.

* ``base.html.twig``: Equivalent to ``::base.html.twig`` and **recommended**
for application-wide templates.

In the :ref:`overriding-bundle-templates` section, you'll find out how each
template living inside the ``AcmeBlogBundle``, for example, can be overridden
by placing a template of the same name in the ``app/Resources/AcmeBlogBundle/views/``
directory. This gives the power to override templates from any vendor bundle.

.. tip::

Hopefully the template naming syntax looks familiar - it's the same naming
convention used to refer to :ref:`controller-string-syntax`.
Hopefully the template naming syntax looks familiar - it's similair to the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: similair -> similar

naming convention used to refer to :ref:`controller-string-syntax`.

Template Suffix
~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -1322,7 +1322,7 @@ covered:
template is called ``base.html.twig``;

* Create a template for each "section" of your site. For example, the blog
functionality would have a template called ``/Blog/layout.html.twig`` that
functionality would have a template called ``Blog/layout.html.twig`` that
contains only blog section-specific elements;

.. code-block:: html+jinja
Expand Down
0