Skip to content

Explain how to override the default templates directory #7844

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 1 commit into from
May 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions configuration/override_dir_structure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ directory structure is:
│ ├─ cache/
│ ├─ config/
│ ├─ logs/
│ ├─ Resources/
│ │ └─ views/
│ └─ ...
├─ src/
│ └─ ...
Expand Down Expand Up @@ -80,6 +82,22 @@ method::

Here you have changed the location of the directory to ``app/{environment}/logs``.

.. _override-templates-dir:

Override the Templates Directory
--------------------------------

If your templates are not stored in the default ``app/Resources/views/``
directory, use the :ref:`twig.paths <config-twig-paths>` configuration option to
define your own templates directory (or directories):
Copy link
Contributor

Choose a reason for hiding this comment

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

What about mentioning the root dir here? Either via a note or %kernel.root_dir%/Resources/views/ instead of app/Resources/views/. This will be one of the things people will forget to change once they move their kernel to src/. People already are in the process of doing so now that the structure for 4.0 has been presented.

Copy link
Contributor

Choose a reason for hiding this comment

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

What about mentioning the root dir here? Either via a note or %kernel.root_dir%/Resources/views/ instead of app/Resources/views/.

I agree we should explicit it at some point but I don 't think this is the right place to do so, since other resources are concerned (i.e translations).

The whole Resources folder should be relative to the kernel root dir.


.. code-block:: yaml

# app/config/config.yml
twig:
# ...
paths: ["%kernel.root_dir%/../templates"]

.. _override-web-dir:

Override the ``web`` Directory
Expand Down
2 changes: 2 additions & 0 deletions reference/configuration/twig.rst
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ on. Set it to ``0`` to disable all the optimizations. You can even enable or
disable these optimizations selectively, as explained in the Twig documentation
about `the optimizer extension`_.

.. _config-twig-paths:

paths
~~~~~

Expand Down