Diego Bastidas
Diego Bastidas

Reputation: 63

How to put a html tag (span) inside a button in twig file symfony 2.8?

I have been trying to customize a form individual field, following the symfony documentation: http://symfony.com/doc/master/form/form_customization.html#how-to-customize-an-individual-field

But I have not had success in my attempt. This is my twig:

{% block _Formulario_personalizado_widget %}
                <span class="icon-icon-buscar-libros fs1"></span>
            {% endblock %}

            {{ form_widget(Formulario.Buscar, {'id':"BuscarPorCriterio", 'attr':{'class':'btn btn-primary active'}}) }}

This is my form in the cotroller:

 ->add('Buscar',ButtonType::class, array('block_name'=> 'personalizado'))

And this controller returns a twig with next form name:

array("Formulario"=>$form->createView())

However, the output is like this:

<span class="icon-icon-buscar-libros fs1"></span>

            <button type="button" id="BuscarPorCriterio" name="form[Buscar]" class="btn btn-primary active">Buscar</button>

And I actually need this output (with SPAN INSIDE Button):

<button type="button" id="BuscarPorCriterio" name="form[Buscar]" class="btn btn-primary active"><span class="icon-icon-buscar-libros fs1"></span> Buscar</button>

Thank you in advance for your help!

Upvotes: 1

Views: 1573

Answers (1)

Dan Costinel
Dan Costinel

Reputation: 1736

Usually, the submit buttons are not created inside the controller, nor the Type, but you can create them in the twig template directly. Like:

{% form_start(Formulario) %}
    {% form_row(Formulario.field) %}
    {# more fields here #}

    <button type="button">
        <span class="icon-icon-buscar-libros fs1"></span>
        Buscar
    </button>
{% form_end(Formulario) %}

Upvotes: 3

Related Questions