gpt4 book ai didi

php - Symfony Twig 覆盖特定的表单行

转载 作者:可可西里 更新时间:2023-11-01 13:22:45 24 4
gpt4 key购买 nike

我有一个表单 Twig 模板,我想在其中使用原始过滤器(它包含 html)解析特定字段的帮助文本。该字段在名为 Clinic 的表单中称为邮政编码

根据这里http://symfony.com/doc/current/cookbook/form/form_customization.html#how-to-customize-an-individual-field

表单模板:

{% 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 %}

任何人都可以看到我忽略了什么,我试过了

{% block _clinic_postcode_row %}

{% block _Clinic_postcode_row %}

解决方案

根据接受的答案,表单行 block 需要使用速记包名称完全识别。最简单的方法是查看表单的源代码并识别每个输入字段和表单名称中使用的文本 name="":

enter image description here

最佳答案

替换

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

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

由于您在操作模板中装饰行,因此在应用单独的表单模板时您需要指定多个模板

您还需要为行 block 指定一个完全限定的路径名​​,例如

{% block _agrihealth_ahpbundle_clinic_postcode_row %}

关于php - Symfony Twig 覆盖特定的表单行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27283612/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com