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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Support

Update-safe overrides for forms fields twig templates?

form

Solved by art View solution

Started by art 8 years ago · 5 replies · 811 views
8 years ago

Hi there! While creating site using Grav CMS, I had to make some changes to .twig templates of some form's fields. So, for beginning I just changed some .twig files, for example
/user/plugins/form/templates/forms/fields/checkbox/checkbox.html.twig
and
/user/plugins/form/templates/forms/fields/select/select.html.twig

Of cause, all my edits just were overwritten and lost during first attempt to update Grav and I've got the sabe basic versions that I've started from.

Ok, so I created special folders that were not exist before, and placed my templates there:
/user/plugins/form/templates/forms/fields/checkbox_special/checkbox_special.html.twig
and
/user/plugins/form/templates/forms/fields/select_special/select_special.html.twig

I thought, that as long as these folders are not native to plugin, they will stay intact during next update.

It seems that I was wrong, and while next update, these folders were again just wiped out, so my special fields just gone from form page.

So I have one very specific question: where should I place these twig templates, so that they keep on working and wouldn't be wiped out again on next update??

Please, note, I don't want to override WHOLE plugin, just a couple of templates for couple specific form fields.

Thanks in advance!

8 years ago

Hi, put them in user/themes/<themename>/templates/forms/... and replicate the path structure you see in the default plugin templates.

Are you using a child theme? If not, your theme will also be overwritten by an update.

I'm hoping that in the near future, Grav's updaters will warn you about overwriting modified plugins and themes. Before that, you learn pretty quickly to put your modifcations in the correct safe places :anguished:

8 years ago

Hi again, I'm using Gantry Helium theme along with gantry plugin, there is no "/templates/" sub-folder in "/themes/ < themename > " folder. I created it manually, following instructions, but no luck. Any ideas?

8 years ago Solution

UPDATE:
ok, I've played a bit, and it seems that in case of Gantry framework correct path is:

/user/plugins/gantry5/engines/nucleus/templates/forms

and then replicate the path structure you see in the default plugin templates.

8 years ago

If you created an inherited theme, I don't know this, but possibly it doesn't create a templates subfolder because there aren't any yet.

So try creating that "templates" folder and any subfolders required to put your overriding templates in the same location. Double-check that your new folders and files have the same ownership and file permissions as the parent theme.

8 years ago

thanks, I already figured out the solution.

Suggested topics

Topic Participants Replies Views Activity
Support · by Thomas, 1 week ago
3 90 1 hour ago
Support · by Anna, 3 days ago
2 92 22 hours ago
Support · by Justin Young, 23 hours ago
1 40 23 hours ago
Support · by Duc , 1 week ago
2 98 6 days ago
Support · by Colin Hume, 1 week ago
2 90 6 days ago