grav-plugin-form icon indicating copy to clipboard operation
grav-plugin-form copied to clipboard

Can't override form_field_extra_wrapper_classes in child template

Open SeriousKen opened this issue 3 years ago • 3 comments

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 %}

SeriousKen avatar Jan 16 '21 15:01 SeriousKen

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.

mahagr avatar Jan 18 '21 09:01 mahagr

@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.

SeriousKen avatar Jan 18 '21 10:01 SeriousKen

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...

mahagr avatar Jan 18 '21 18:01 mahagr