Can I put html inside a Symfony form button with Twig?

前端 未结 5 1587
暗喜
暗喜 2021-02-02 09:06

I\'m trying to put html inside a form button with twig like:

{{ form_widget(form.jiraStatus, {
        \'label\': \'Bug\',         


        
5条回答
  •  孤独总比滥情好
    2021-02-02 09:37

    On Symfony 5.1, you can add html content into button label like this:

    {{ form_widget(form.submit, { 'label': ' Calculate prices', 'label_html' : true })}}
    

    You need to pass the option "label_html" : true

    You can view the original Symfony/Twig code from form_div_layout.html.twig file to understand it:

    {%- block button_widget -%}
        {%- if label is empty -%}
            {%- if label_format is not empty -%}
                {% set label = label_format|replace({
                    '%name%': name,
                    '%id%': id,
                }) %}
            {%- elseif label is not same as(false) -%}
                {% set label = name|humanize %}
            {%- endif -%}
        {%- endif -%}
        
    {%- endblock button_widget -%}
    

提交回复
热议问题