2016-07-29 130 views
1

所以我有這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。

謝謝

回答

3

第二個參數應該是標籤文本或null。

{{ form_label(form.type[0], null, {"label_attr":{"class":"myclasshere"}}) }} 
1

的類是標籤標記的屬性,所以在嫩枝它應該的「ATTR」陣列這樣在被寫成:

{{ form_label(form.type[0], {"attr":{"class":"myclasshere"}}) }}