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
Changed Bundle:Controller:Template to bundle:dir:file
  • Loading branch information
wouterj committed Nov 6, 2014
commit a8a75d79de3834744ad12061ae239028e0e0bfec
21 changes: 11 additions & 10 deletions book/templating.rst
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,10 @@ By default, templates can live in two different locations:
plan to share your bundle, you should put the templates in the shared bundle
instead of the ``app/Resources/views`` directory.

Symfony uses a **bundle**:**controller**:**template** string syntax for
templates. This allows for several different types of templates, each which
lives in a specific location:
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, 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
template for a specific page. The three parts of the string, each separated
Expand All @@ -402,26 +403,26 @@ lives in a specific location:
* ``AcmeBlogBundle``: (*bundle*) the template lives inside the
``AcmeBlogBundle`` (e.g. ``src/Acme/BlogBundle``);

* ``Blog``: (*controller*) indicates that the template lives inside the
* ``Blog``: (*directory*) indicates that the template lives inside the
``Blog`` subdirectory of ``Resources/views``;

* ``index.html.twig``: (*template*) the actual name of the file is
* ``index.html.twig``: (*filename*) the actual name of the file is
``index.html.twig``.

Assuming that the ``AcmeBlogBundle`` lives at ``src/Acme/BlogBundle``, the
final path to the layout would be ``src/Acme/BlogBundle/Resources/views/Blog/index.html.twig``.

* ``AcmeBlogBundle::layout.html.twig``: This syntax refers to a base template
that's specific to the ``AcmeBlogBundle``. Since the middle, "controller",
that's specific to the ``AcmeBlogBundle``. Since the middle, "directory",
portion is missing (e.g. ``Blog``), the template lives at
``Resources/views/layout.html.twig`` inside ``AcmeBlogBundle``.
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 an application-wide base template
or layout. Notice that the string begins with two colons (``::``), meaning
that both the *bundle* and *controller* portions are missing. This means
that the template is not located in any bundle, but instead in the root
* ``::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**
Expand Down
0