Random setting css on cookie session

♪ Bonjour !

Thank you again for yesterday: to me, coding my first site with Grav has becomed exciting: I am amazed to be able to code what I code and now I look foward to have nearly everything the way I want, which is exceptionnal if you consider my technical level!

I’d like to ask something that is still technically out of my range.

I would like to have, let’s say for convenience, changing colors in some places for each visit to my site.

For instance,
today, first visit, this button is red
but
tomorrow, second visit and its may be blue.

Color would change in a range of predefined set colors in css.

In theory, that is probably possible with the session cookie as for the language setting, no?

But how would you do that?

(hoping the question is not to hard)

precision: I am with the antimatter theme modified by a mytheme layer as in the example of learn.getgrav.org

François V. alias Tidivoit

This is a rather specific request, but I guess you could mimic the functionality here: http://supergeekery.com/geekblog/comments/change_your_css_styles_based_on_the_day_with_expression_engine

You would of course need to port this to Twig so you could have it in your template files of your theme.

Thanks for reply: I’ll have a look.

I am asking something else:
How to link parameter to session cookie?

I would like to have continuous setting on a session and changes as soon as session changes.

I agree it’s may be a difficult question…

it’s not difficult, but will require you to write a simple custom plugin that looks for that specific parameter and then sets it on the session. Also you probably want to store the state of the session variable in Twig as a variable so you can reference it from there if needed.

I see … a plugin … right now, it’s out of range of possible, but I have the point and I’ll keep that in mind for later …
Once you have this variable in Twig, do you use it with the random method that appeared somewhere in learn.getgrav.org?
Thank you very much for that answer
I remember a part of learn.getgrav.org is about plugins and how to write them…

Grav has a randomize twig filter… so you can pass an array and it will return a random item from that array.

♪ thanks you very much!