Symfony 2.8 форма динамической генерации choice_label raw twig

1

Я хочу сделать ярлык исходной формы, у меня есть следующий тип объекта формы

    $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 %}

но я получаю этот html

<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
    Укажите ошибку, которую вы получаете.
Теги:
forms
twig
symfony-2.8

1 ответ

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 %}

и, похоже, работает

Ещё вопросы

Сообщество Overcoder
Наверх
Меню