2015-12-08 48 views
1

我想呈現原始形式的標籤,我有以下形式的實體類型Symfony的2.8形式動態生成CHOICE_LABEL生枝

$builder 
     ->add('subscriptionBilling', 'entity', array(
      'class'   => 'AppBundle\Entity\SubscriptionBilling', 
      'data_class' => 'AppBundle\Entity\SubscriptionBilling', 
      'choice_label' => function ($allChoices, $currentChoiceKey) { 
        return '<p>Categories <strong>'.$allChoices->getNoOfCategories().' number</strong> '.$currentChoiceKey.'</p>'; 
      }, 
      'choices'  => $options['packages_allowed'], 
      'data'   => $options['selected_subscriptionBilling'], 
      'multiple'  => false, 
      'expanded'  => true, 
      'required'  => true, 
      'label'   => false, 
     )) 
     ; 

和我的樹枝

{% autoescape false %} 

{{form_label(form_categories.subscription.subscriptionBilling)|raw}} 
{{form_widget(form_categories.subscription.subscriptionBilling)|raw}} 

{% endautoescape %} 

,但我得到這個網站

<p>Categories <strong>5 number</strong> 0</p> 
<p>Categories <strong>10 number</strong> 1</p> 
<p>Categories <strong>25 number</strong> 2</p> 
<p>Categories <strong>10 number</strong> 3</p> 
+0

提供你得到錯誤。 – Mantas

回答

1

我終於創建了一個表單主題,它擴展了引導表單佈局

{% extends 'bootstrap_3_layout.html.twig' %} 
{% block radio_label %} 
    {# Do not display the label if widget is not defined in order to prevent double label rendering #} 
    {% if widget is defined %} 
     {% if required %} 
      {% set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' required')|trim}) %} 
     {% endif %} 
     {% if parent_label_class is defined %} 
      {% set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' ' ~ parent_label_class)|trim}) %} 
     {% endif %} 
     {% if label is not same as(false) and label is empty %} 
      {% set label = name|humanize %} 
     {% endif %} 
     <label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}> 
      {{- widget|raw }} {{ label is not same as(false) ? (translation_domain is same as(false) ? label|raw : label|trans({}, translation_domain)|raw) -}} 
     </label> 
    {% endif %} 
{% endblock radio_label %} 

和我的樹枝

{% autoescape %} 
{{form_label(form_categories.subscription.subscriptionBilling)}} 
{{form_widget(form_categories.subscription.subscriptionBilling)}} 
{% endautoescape %} 

,它似乎工作