Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Form fields layout customization?

Started by Muut Archive 10 years ago · 2 replies · 409 views
10 years ago

How can I customize form fields so that I can use my own layout but at the same time not lose all the logic and updates already built into the form plugin?

I'm using bootstrap and want to apply more classes at more levels than the outerclasses and classes fields currently offer. I was going through the bootstrap theme form fields but they look like cut down versions of the plugin fields which would then require a lot of manual maintenance to keep up to date. I want to keep the form plugin logic but have more control over the field layouts at the same time.
Is this possible? I'm not sure twig inheritance really allows this. Any suggestions? Thanks

10 years ago

You would need to add a twig path via a plugin event (pretty much every plugin does this.. for example: https://github.com/getgrav/grav-plugin-breadcrumbs/blob/develop/breadcrumbs.php#L37-L40

Then you just need to copy and edit the appropriate form plugin's twig templates: https://github.com/getgrav/grav-plugin-form/tree/develop/templates/forms/fields

You will want to ensure your event has a higher number than the form plugin's, for example:

JS
'onTwigTemplatePaths'        => ['onTwigTemplatePaths', 1000],

Make sure you keep the same directory structure and filenames the same.

10 years ago

@rhukster:
could you please go into deeper detail how this is done?

What are the exact steps I need to do?
Where do I need to define this number for the event?

Thanks in advance!

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1362 9 years ago
Archive · by Muut Archive, 9 years ago
2 940 9 years ago
Archive · by Muut Archive, 9 years ago
2 4069 9 years ago
Archive · by Muut Archive, 9 years ago
1 2959 9 years ago
Archive · by Muut Archive, 9 years ago
3 1124 9 years ago