Skip to content

Instantly share code, notes, and snippets.

@laurentsab
Created January 20, 2016 09:02
Show Gist options
  • Save laurentsab/f04a75549b31b893f31c to your computer and use it in GitHub Desktop.
Save laurentsab/f04a75549b31b893f31c to your computer and use it in GitHub Desktop.
Twig merge attributes
// parent_template.html.twig
{% include "AppBundle:fields:input_text.html.twig" with {
'form_id': form_id,
'field_name': 'Numéro',
'required': true,
'attr': {
'data-minlength': '\\d{7}',
'minlength': '7',
'maxlength': '7',
'data-error': 'e0.message_error'|trans()
},
} %}
// input_text.html.twig
{{ form_widget(form_field, {
'attr': {'class': 'form-control margin_bottom_10px'}|merge( attr|default({}) ) } )
}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment