Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Pages object from modular template?

Started by Muut Archive 11 years ago · 8 replies · 615 views
11 years ago

I can't figure out how to access the pages object from a module template as such:

TWIG
{% for page in pages.children %}
  {{ page.title }}
{% endfor %}

By modular template I mean:
/user/themes/theme-name/templates/modular/module-template.html.twig

11 years ago

pages.children accepts a path, the page you route you want to inspect. see API

page.children on the other hand returns the children of the current page. API

On a modular child page, page.children usually is not set, do you want the parent page children? In this case you can get page.parent.children

11 years ago

Ok I think we're on the right track. Actually I want the root for all the pages /users/pages/ but `pages.find('/').children' doesn't return anything.

11 years ago

pages.find('/') returns the home page. You want pages.all

11 years ago

I guess I'd need a code example to make pages.all work, cause it's not.

11 years ago

My mistake. pages is a link to the root page (/users/pages/) so you can do

TWIG
{% for page in pages.children %}
  {{ page.title }}
{% endfor %}
11 years ago

lol, we've come full circle.. if you see the top of my post, I did exactly that. The problem is that it doesnt work from a template in templates/modular/template.html.twig

11 years ago

Ouch!
You're right it seems the pages object is not directly accessible in modular childs. Use

TWIG
{% for page in grav.pages.root.children %}
  {{ page.title }}
{% endfor %}
11 years ago

THANK YOU! Jeez that was messing with my head. You're a god among insects! :)

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 2000 9 years ago
Archive · by Muut Archive, 9 years ago
2 1342 9 years ago
Archive · by Muut Archive, 9 years ago
2 4549 9 years ago
Archive · by Muut Archive, 9 years ago
1 3402 9 years ago
Archive · by Muut Archive, 9 years ago
3 1494 9 years ago