Closed ctuxboy closed 5 years ago
The Twig variable pages
is a list of all pages, indexed by page ID. There's no Twig variable page
(without s
), unless you define it; page.title
refers to the pages loop shown below:
{% for page in pages if not page.hidden %}
<p>{{ page.title }}</p>
{% endfor %}
This snippet tells Twig to iterate the pages
list and assign the currently iterated item to the page
variable, allowing you to print out the page's title using {{ page.title }}
.
If you want to access the current page, use the current_page
variable, e.g. {{ current_page.title }}
.
@PhrozenByte thanks for your help!
The reason trying this is building a theme with a 'hidden' md-file:
_social.md
Trying out for show in a current page, the only way i found is this:
{{ pages._social.meta.icon }}
Is this the right way, for doing this?
Yes.
I'd just recommend using a slightly different syntax. The current syntax doesn't allow you to access pages in sub dirs (like sub/page.md
). Use {{ pages["_social"].meta.icon }}
instead.
Oh okay, now i understand. Thanks a lot for your help! Looking in several themes; but couldn't find a good example.
Thanks a lot man :)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in two days if no further activity occurs. Thank you for your contributions! :+1:
Hello,
I'm experimenting with twig variables in pico themes. Reading this document
So trying this:
<p>{{ page.intro.title }}</p>
Doesn't work!<p>{{ pages.intro.title }}</p>
Shows the title from the intro.md file!So if i understand, filter the right page, when the first parameter needs pluralize pages ?
In the docs, the variables:
page.id
page.url
page.title
... are singular.It is confusing.