Symfony Twig overrides a specific form line

I have a form branch template where I want to parse help text for specific fields with a raw filter (it contains html). The field is called a zip code in the form of Clinic

According to this http://symfony.com/doc/current/cookbook/form/form_customization.html#how-to-customize-an-individual-field

Shape Template:

{% extends 'AgriHealthAhpBundle::admin.html.twig' %} {% form_theme form 'AgriHealthAhpBundle:Form:fields.html.twig' %} {% block _clinic_postcode_row %} <div class="row"> test<div class="small-12 medium-3 columns label">{{ form_label(form) }}</div> <div class="small-12 medium-6 columns widget"> {{ form_widget(form) }} <div class="error"> {{ form_errors(form) }} </div> </div> <div class="small-12 medium-3 columns help"> {% if help is defined %} {{ help|raw }} {% endif %} </div> </div> {% endblock %} {% block admin -%} <h1>New Clinic</h1> {{ form(form) }} <div class="row form_actions"> <div class="small-12 medium-offset-3 medium-2 columns submit"> <button type="submit" id="agrihealth_ahpbundle_clinic_submit_visible" name="agrihealth_ahpbundle_clinic[submit]">Create</button> </div> <script type="text/javascript"> jQuery(document).ready(function() { jQuery('#agrihealth_ahpbundle_clinic_submit_visible').click(function(){ jQuery('form[name="agrihealth_ahpbundle_clinic"]').submit(); }); }); </script> <div class="small-12 medium-2 columns cancel"> <a href="{{ path('clinic') }}"> Cancel </a> </div> <div class="small-12 medium-2 end columns cancel"> <a href="{{ path('clinic') }}"> Back to List </a> </div> </div> {% endblock %} 

AhpBundle / Resources / views / Form / fields.html.twig

 {% block form_row %} {% spaceless %} <div class="row"> <div class="small-12 medium-3 columns label">{{ form_label(form) }}</div> <div class="small-12 medium-6 columns widget"> {{ form_widget(form) }} <div class="error"> {{ form_errors(form) }} </div> </div> <div class="small-12 medium-3 columns help"> {% if help is defined %} {{ help }} {% endif %} </div> </div> {% endspaceless %} {% endblock form_row %} 

Anyone can see what I missed, I tried

 {% block _clinic_postcode_row %} 

and

 {% block _clinic_postcode_row %} 

Decision

In accordance with the accepted answer, the block of form lines should be fully identified with the abbreviated name of the bundle. The easiest way is to view the source code of the form and determine the text used in each input field, and the form name = "":

enter image description here

+6
source share
1 answer

Replace

{% form_theme form 'AgriHealthAhpBundle:Form:fields.html.twig' %}

with

{% form_theme form with ['AgriHealthAhpBundle:Form:fields.html.twig', _self] %}

Since you decorate a line inside an action template using a separate form template, you need to specify several templates

You also need to specify the full path name of the string block, for example

 {% block _agrihealth_ahpbundle_clinic_postcode_row %} 
+5
source

Source: https://habr.com/ru/post/979079/


All Articles