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

前端 未结 5 1591
暗喜
暗喜 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:39

    If you're looking for a simpler solution, just insert this into your form theme:

    {%- block button_widget -%}
        {% set attr = attr|merge({class: (attr.class|default('btn-default') ~ ' btn')|trim}) %}
        {%- if label is empty -%}
            {%- if label_format is not empty -%}
                {% set label = label_format|replace({
                    '%name%': name,
                    '%id%': id,
                }) %}
            {%- else -%}
                {% set label = name|humanize %}
            {%- endif -%}
        {%- endif -%}
        
    {%- endblock button_widget -%}
    

    You can then go ahead and insert HTML in your button label:

    {{ form_widget(searchForm.search, {'label': ''}) }}
    

提交回复
热议问题