Overwriting the $page variable

I was wondering if there was a way for me to overwrite the $page variable within a controller/model/snippet or plugin, so that the new $page variable would be usable throughout all of my other snippets and be kept alive, instead of beeing overwritten again by kirby.

Currently if I were to overwrite the kirby generated $page in a controller for example, the value wont be my overwritten value if I was to call $page somewhere else later on, like in a template or a snippet.

You could if you pass the variable to the template and snippet. But why don’t you use a different variable instead?

Because depending on the subdomain of the website, different “startingpoints” in the backend need to be used (if they exist, and if not they need to fetch the original content).
I have tried passing $page from the controller to the template, sadly even then it will get overwritten.

I guess using a seperate non kirby variable could be the best to do here.

So if I had a blogone.website.com/fish/detail $page would have to be the page with the uid “blogone/fish/detail”
In blogtwo.website.com/fish/detail $page would have to be the page with the uid “blogtwo/fish/detail”
(Both sites are hosted in the same backend).

Im guess im mainly looking for a way, to have a variable that does not have to be passed to every single snippet again from the template.

Also: happy birthday!

Thank you!

As long as you pass the variable from the controller to the template, this variable is also available in snippets that are called from this template.

1 Like

Thank you very much!