diff --git a/form/create_custom_field_type.rst b/form/create_custom_field_type.rst index 63f07ef8974..76ed91c9593 100644 --- a/form/create_custom_field_type.rst +++ b/form/create_custom_field_type.rst @@ -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 + 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 --------------------------------- diff --git a/form/form_customization.rst b/form/form_customization.rst index f5ab9ef2dc5..f6205819526 100644 --- a/form/form_customization.rst +++ b/form/form_customization.rst @@ -735,6 +735,36 @@ class to the ``div`` element around each row: {% 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 + + 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 %} +
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: