Skip to content

[Form] Mention that form_theme _self only works with template inheritance #11021

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
Feb 21, 2019
Merged
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
14 changes: 10 additions & 4 deletions form/form_themes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ for any overridden form blocks:

.. code-block:: html+twig

{% extends 'base.html.twig' %}

{% form_theme form _self %}

{# this overrides the widget of any field of type integer, but only in the
Expand All @@ -359,12 +361,16 @@ for any overridden form blocks:
</div>
{% endblock %}


{# ... render the form ... #}

The disadvantage of this method is that the customized form blocks can't be
reused when rendering other forms in other templates. If that's what you need,
create a form theme in a separate template as explained in the next section.
The main disadvantage of this method is that it only works if your template
extends another (``'base.html.twig'`` in the previous example). If your template
does not, you must point ``form_theme`` to a separate template, as explained in
the next section.

Another disadvantage is that the customized form blocks can't be reused when
rendering other forms in other templates. If that's what you need, create a form
theme in a separate template as explained in the next section.

Creating a Form Theme in a Separate Template
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down