Symfony2:标签内部的自定义HTML
问题描述:
Symfony 2表单在标签内添加HTML有没有办法?Symfony2:标签内部的自定义HTML
我想:
<label for="myfield"><span class="photo">My label</span></label>
我怎么能写呢?如预期的这些想法 无正确:
<span class="photo">{{ form_label(form.myfield) }}</span>
或者
{{ form_label(form.myfield, '<span class="photo">'~myfield~'</span>') }}
感谢您的帮助, 一个
答
看看到Symfony2 Form theming文件,特别是对 “Adding a "Required" Asterisk to Field Labels” 部分。
我不确定这是最好的方法,但它应该工作。
答
我想你可以做这样的:
enter code here
{{ form_label(form.myfield,'Name of the label') }}
{{ form_errors(form.myfield)}}
{{ form_widget(form.myfield),{attr:{'class':'photo span'}}) }}
第一个想法行不通?为什么?我的意思是,它应该:) – 2012-04-02 10:59:54
因为
“你在你的第二个例子(而不是')只是一个复制/粘贴错误? – Cerad 2012-04-02 13:40:28