如何更改Symfony2.8/Twig中单选按钮的标签类别?
问题描述:
所以我有这2个代码:如何更改Symfony2.8/Twig中单选按钮的标签类别?
我的PHP代码
$builder
->setMethod("GET")
->add(
"type"
, "choice"
, array(
"choices" => array("student"=>"Student ID", "hr"=>"HR number")
, "expanded" => true
, "label_attr" => array(
"class" => "myclasshere"
)
, "multiple" => false
, "required" => false
)
我的树枝模板:
{{ form_label(form.type[0]) }}
我的问题是,没有阶级被应用于标签。
我也试过:
{{ form_label(form.type[0], {"label_attr":{"class":"myclasshere"}}) }}
这给了一个错误。
任何想法如何完成?我的选择是自己写标签标签而不是使用Twig。
谢谢
答
第二个参数应该是标签文本或null。
{{ form_label(form.type[0], null, {"label_attr":{"class":"myclasshere"}}) }}
答
的类是标签标记的属性,所以在嫩枝它应该的“ATTR”阵列这样在被写成:
{{ form_label(form.type[0], {"attr":{"class":"myclasshere"}}) }}