Not sure where youâve added this, but chances are, your first declaration of $h is not actually in the global spaceârather, its context is that of a Kirby method.
You may want to try Kirbyâs internal data silo, c:
c::set('h', 1);
function example () {
echo c::get('h');
}
This is the recommended way to exchange info globally, in a Kirby application. Itâs often used for config, temporary object storage, etc.
I know this isnât a technically precise answer or solution, but I hope itâs useful!
I am attempting a recursive function that walks my pages tree and does some things with the pages, and I needed a variable outside of the function that could be accessed from within.
Although it seems as if the set get procedure is simple, I canât find many examples of it. Toolkit docs are mostly empty about it.
I assume I need to get the value into a variable in order to manipulate it, so:
Using global variables in something simple like a home page template? I think this is one of those scenarioâs where you shouldnât be wondering if you can, but if you shouldâŚ
There is probably a better way to achieve what youâre trying to do!