![](/img/trans.png)
[英]Symfony2: How to properly include assets in conjunction with Twig template inheritance?
[英]how to change a label template using twig inheritance in symfony2
使用帶有Twig的Symfony2.3.4。
假設我正在嘗試添加冒號(:),如果需要 ,還可以在Symfony2的CRUD生成的表單中的每個字段的每個標簽上添加一個星號(*)。 為此,我使用twig模板繼承Symfony2的主模板form_div_layout.html.twig 。
至今:
//config.yml
twig:
form:
resources:
- ::my_form_layout.html.twig
//my_form_layout.html.twig
{% block form_label %}
{% spaceless %}
{% if label is not sameas(false) %}
...
{% set asterisk = '<sup><i title="Campo obligatorio"
class="glyphicon-asterisk" style="color: red; font-size:
8px"></i></sup>' %}
<label {% for attrname, attrvalue in label_attr %}
{{ attrname }}="{{ attrvalue }}"{% endfor %}>
{{ label|trans({}, translation_domain) }}: {% if required %}
{{ asterisk|raw }} {% endif %}
</label>
...
{% endif %}
{% endspaceless %}
{% endblock form_label %}
例如,當我渲染一個用於選擇人的性別的選擇類型字段時,問題就是這種方式, 擴展且必需設置為TRUE ,冒號(:)和星號(*)出現在單詞Sex AND旁邊男性和女性也是如此。
如何使模板在父項和兩個子項之間區分,因此冒號和星號僅在單詞Sex之后出現。
感謝名單
這就是我做類似的事情。 在自定義表單布局中稍微修改“choice_widget_expanded”塊:
// update this row: {{ form_label(child) }}
{{ form_label(child, child, {'exclude_additions': 'true'}) }}
並更新您的'form_label'以檢查是否定義了此值:
{{ label|trans({}, translation_domain) }}{% if exclude_additions is not defined %}: {% if required %}
{{ asterisk|raw }} {% endif %} {% endif %}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.