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.

Plugins

Hook into theme config save event?

admin

Solved by Anna View solution

Started by Anna 4 years ago · 6 replies · 411 views
4 years ago

I would like to manipulate a theme file whenever the theme settings are saved. I'm not sure how to check for that though… Would I best do this on AdminSave or onAdminAfterSave?

And I tried dumping things on these hooks, but nothing turns up in the debugger. var_dump('?') gives me nothing, dump('?') doesn't either.

Your ideas are much appreciated!

4 years ago

@Netzhexe:
manipulate a theme file

? Which file exactly and why? Sounds very suspicious

4 years ago

Heh, yeah. I've thought about the best way to do this, but so far nothing seems optimal.

The file I would like to manipulate is the input.css file from my Tailwind configuration. I'd like to change a few classes based on a theme setting. If I can't think of a better way, I'll do it manually… but switching a theme setting and then having everything change accordingly would really be very nice.

4 years ago

You don't have to change file and that would be discouraged. I would try something like custom TW theme switching depending on data attribute. And this data attribute should be changed depending on Grav theme setting. Would need more research for me to tell for sure if this is the way, but definitely not file manipulation

4 years ago

Hmmm, yeah no, can't do it with CSS variables. Loading a different preset would be ok, but how would I do THAT on changing a config setting?

Apart from that, I think manipulating the file would be ok in my case. It's my own theme and it won't be used by others. Basically I just want to save myself from having to do it manually.

4 years ago

In your theme class you can define what assets to load based on any config setting, I think 🤔

4 years ago Solution

Yes… the thing is, I don't want to generate x versions of css just in case I might need them. I'd rather change a few variables dynamically. Now, this is quite possible with CSS variables of course, but that didn't work for my original problem. I wasn't thinking straight though, it was easily doable with an extra class 😅

last edited 09/29/22 by pamtbaau

Suggested topics

Topic Participants Replies Views Activity
Plugins · by Rene, 1 week ago
2 43 1 week ago
Plugins · by Xavier, 4 weeks ago
2 53 4 weeks ago
Plugins · by Luka Prinčič, 7 years ago
3 1179 1 month ago
Plugins · by Sebastian van de Meer, 1 month ago
1 48 1 month ago
Plugins · by PIERROT Alain, 2 months ago
3 72 2 months ago