getgrav / grav-plugin-form

Grav Form Plugin
http://getgrav.org
MIT License
53 stars 79 forks source link

Can't override form_field_extra_wrapper_classes in child template #483

Open SeriousKen opened 3 years ago

SeriousKen commented 3 years ago

https://github.com/getgrav/grav-plugin-form/blob/fab75139696d15bc9be0438f6649fb1ee2161327/templates/forms/default/field.html.twig#L91-L92

The default field template explicitly sets form_field_extra_wrapper_classes in a way that can't be overridden in a child template due to the way Twig handles template inheritance.

I'm currently writing a plugin to integrate Bootstrap 5 and need a way to set classes on this section:

https://github.com/getgrav/grav-plugin-form/blob/fab75139696d15bc9be0438f6649fb1ee2161327/templates/forms/layouts/field.html.twig#L43-L49

without having to touch the field template. This could be fixed if line 92 in default/field.html.twig was changed to:

{% set form_field_extra_wrapper_classes = ((form_field_extra_wrapper_classes ?: 'form-extra-wrapper ') ~ ' ' ~ field.wrapper_classes)|trim %}
mahagr commented 3 years ago

IMHO: This would be better:

{% set form_field_extra_wrapper_classes = form_field_extra_wrapper_classes ?? ('form-extra-wrapper ' ~ field.wrapper_classes) %} 

Just simpler and gives all the power to the theme.

SeriousKen commented 3 years ago

@mahagr that wouldn't work as field.wrapper_classes wouldn't be applied if form_field_extra_wrapper_classes was set. I've just copied the implementation for other form_field_... variables in the default/field.html.twig file.

mahagr commented 3 years ago

Well, it really depends if those classes are wanted or if you're allowed to do your own implementation. You are right, though, it requires theme devs to copy and modify the line...