Add unfold
Hello @tsnorri, thanks for your contribution! Calculating Fibonacci numbers is a quite abstract example. Especially since most calculations in web apps are not done in templates, but rather in controller. Could you please provide a more down-to-earth example of use?
I just noticed your question, sorry about the rather long delay. A more down-to-earth use case would be traversing a page hierarchy from a non-root towards the root, i.e. by using parent() or similar. This would be useful in e.g. creating a breadcrumb list. I don’t have sample code right now but I can try to produce something.
Something like this:
{% set breadcrumbs = page|unfold(=> (_ is null or _.root) ? null : [_, _.parent])|reverse %}
Why do you need the _.root check? Isn’t your root’s parent null?
Why do you need the
_.rootcheck? Isn’t your root’s parent null?
Apparently in Grav (at least version 1.4.5) the root isn’t actually a page but a directory. The directory may contain other pages in addition to the designated home page.