Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.3k
[Form] Documenting the block_prefix option#10835
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -87,6 +87,12 @@ The goal of this field was to extend the choice type to enable selection of the | ||
| shipping type. This is achieved by fixing the ``choices`` to a list of available | ||
| shipping options. | ||
| .. tip:: | ||
| If the purpose of this new form type was to customize the rendering of some | ||
yceruto marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| fields only, skip this step and use ``block_name`` or ``block_prefix`` option | ||
| instead. For more information, see :ref:`form-customization-form-themes`. | ||
| Creating a Template for the Field | ||
| --------------------------------- | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -735,6 +735,36 @@ class to the ``div`` element around each row: | ||
| </div> | ||
| {% endblock form_row %} | ||
| .. tip:: | ||
| If you want to customize some instances of the same form only (without | ||
| the need to create a new form type) you can set the ``block_prefix`` | ||
| option in your form type:: | ||
| use Symfony\Component\Form\Extension\Core\Type\TextType; | ||
| use Symfony\Component\Form\FormBuilderInterface; | ||
| public function buildForm(FormBuilderInterface $builder, array $options) | ||
| { | ||
| $builder->add('name', TextType::class, array( | ||
| 'block_prefix' => 'wrapped_text', | ||
| )); | ||
| } | ||
| .. versionadded:: 4.3 | ||
yceruto marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| The ``block_prefix`` option was introduced in Symfony 4.3. | ||
| Then the block name will be ``wrapped_text_row``. | ||
| .. code-block:: html+twig | ||
| {% block wrapped_text_row %} | ||
| <div class="wrapped"> | ||
| {{ form_row(form) }} | ||
| </div> | ||
| {% endblock wrapped_text_row %} | ||
yceruto marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| .. tip:: | ||
| See :ref:`form-theming-methods` for how to apply this customization. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| block_prefix | ||
| ~~~~~~~~~~~~ | ||
| **type**: ``string`` or ``null`` **default**: ``null`` (see :ref:`Knowing which | ||
| block to customize <form-customization-sidebar>`) | ||
| .. versionadded:: 4.3 | ||
yceruto marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| The ``block_prefix`` option was introduced in Symfony 4.3. | ||
| Allows you to add a custom block prefix and override the block name | ||
| used to render the form type. Useful for example if you have multiple | ||
| instances of the same form and you need to personalize the rendering | ||
| of all of them without the need to create a new form type. | ||