我想渲染原始翻譯,所以我決定在樹枝模板中給你'原始'選項。但它不起作用。例如:Symfony2 form_label raw
{{ form_label(form.sfGuardUserProfile.roules_acceptance) | raw }}
在我的網站,我會看到這一點:
Accept the <a href="url_to_pdf">terms</a>
而且我不希望看到的HTML代碼,我想看到的鏈接。如何顯示錶單的原始標籤?
我想渲染原始翻譯,所以我決定在樹枝模板中給你'原始'選項。但它不起作用。例如:Symfony2 form_label raw
{{ form_label(form.sfGuardUserProfile.roules_acceptance) | raw }}
在我的網站,我會看到這一點:
Accept the <a href="url_to_pdf">terms</a>
而且我不希望看到的HTML代碼,我想看到的鏈接。如何顯示錶單的原始標籤?
我也試試這個:http://twig.sensiolabs.org/doc/tags/autoescape.html
{% autoescape false %}
Everything will be outputted as is in this block
{% endautoescape %}
但它不工作。爲什麼?因爲當你使用form_label()函數的Symfony使用\供應商\ symfony的\ symfony中的\ src \的Symfony \橋\嫩枝\資源\意見\表格\ form_div_layout.html.twig和塊:
{% block form_label %}
{% spaceless %}
{% if label is not sameas(false) %}
{% if not compound %}
{% set label_attr = label_attr|merge({'for': id}) %}
{% endif %}
{% if required %}
{% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %}
{% endif %}
{% if label is empty %}
{% set label = name|humanize %}
{% endif %}
<label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>{{ label|trans({}, translation_domain) }}</label>
{% endif %}
{% endspaceless %}
{% endblock form_label %}
我可以試試:
{{ form_label(form.sfGuardUserProfile.roules_acceptance) | raw }}
但raw選項將在form_div_layout.html.twig中被覆蓋。我最終決定做到這一點:
{{ 'form.roules_acceptance'| trans | raw }}
不知道我明白你做了什麼? –
我編輯了我的帖子,如果不解釋我不明白的東西,也許會有所幫助。我會嘗試幫助。 – Purzynski
閱讀這裏:http://symfony.com/doc/current/cookbook/form/form_customization.html
如果字段的名稱讓我們說產品[名]可以覆蓋標籤塊只是個別領域:
{% block _product_name_label %}
<label>{{ label|raw }}</label>
{% endblock %}
,或者例如:
{% block _product_name_label %}
<label>Accept the <a href="url_to_pdf">terms</a></label>
{% endblock %}
只是把代碼在你渲染的形式模板,並添加
{% form_theme form _self %}
所以渲染引擎將搜索同一文件第一
你可以找到\廠商默認的模板文件\ symfony的\ symfony中的\ src \的Symfony \橋\嫩枝\資源\意見\複寫區塊Form \ form_div_layout.html.twig如果您使用完整的堆棧框架。
您是否添加了預期的輸出?爲什麼不使用'form_label'? – ferdynator
因爲在我的翻譯中,我有鏈接到PDF中的條款,這個鏈接被轉義,你不能點擊,因爲你看到網站上的HTML代碼。我想鏈接不是HTML代碼。 – Purzynski