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!