1. How many times does it go through the content?
Does it cache the query the first time, or does it go through the files every time?
$children1 = $page->children();
$children2 = $page->children();
$children3 = $page->children();
2. Same as the first question
$children1 = page()->children();
$children2 = page()->children();
$children3 = page()->children();
3. Why using $page instead of page()?
4. If I ask the same about $site / site(), do I get the same answers?
Yes, it does.
Same as the first question
The result of
is cached as well.
Why using $page instead of page()?
Regarding performance: Less methods need to be called if you use
$page, as that variable is already defined.
page() is more for use in functions with different variable scopes.
In the end it shouldn’t matter which one you use, but
$page also worked in Kirby 1 and is used in examples and themes a lot.
If I ask the same about $site / site(), do I get the same answers?
Awesome! I use
$page is not defined, for example in plugin functions, called from the template.
My first bet who would answer this question was you @lukasbestle. How correct I was! My second bet would be @texnixe.
That’s exactly why
page() exists in Kirby 2.
Yes, we moderators basically live in this forum.
There is some truth in that
@lukasbestle @texnixe I love you both so much for living here