To validate a form I am using a standard:
{{ form_widget(form.save, {'attr': {'class': 'btn btn-sm btn-danger'}, 'label': 'Submit form'}) }}
I want to insert a fontawsome icon in the button. I tried:
{{ form_widget(form.save, {'attr': {'class': 'btn btn-sm btn-danger'}, 'label': '<i class="fa fa-envelope-o"></i> Submit form'}) }}
But it is not working; obviously
Any idea how to that?
Renders the "row" of a given field, which is the combination of the field's label, errors and widget. The second argument to form_row () is an array of variables. The templates provided in Symfony only allow to override the label as shown in the example above. See " More about Form Variables " to learn about the variables argument.
The second argument to form_row () is an array of variables. The templates provided in Symfony only allow to override the label as shown in the example above. See "Twig Template Form Function and Variable Reference" to learn about the variables argument. This renders all fields that have not yet been rendered for the given form.
The templates provided in Symfony only allow to override the label as shown in the example above. See " More about Form Variables " to learn about the variables argument.
The second argument to form_widget () is an array of variables. The most common variable is attr, which is an array of HTML attributes to apply to the HTML widget. In some cases, certain types also have other template-related options that can be passed. These are discussed on a type-by-type basis.
You can just add a new custom service css class per icon
/*
* css selector for a class attribute that starts with "btn-fa-" or has " btn-fa-" in it:
*/
[class^="btn-fa-"]:before,
[class*=" btn-fa-"]:before
{
font-family: "Font Awesome 5 Free";
font-weight: bold;
margin: 0 6px 0 2px;
}
/*
* And then only 1 setting per font awesome class
*/
.btn-fa-plus:before {
content: '\f067';
}
And add the class to the ButtonType
->add('Add an item', ButtonType::class, [
'attr' => [
'class' => 'btn btn-primary btn-fa-plus',
]
])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With