Skip to content
● Grav 2.2 is out: 2x faster cold starts and 96% less memory on big sites. Read the announcement →

Get page collection in a partial template

Solved by Alexander Kim View solution

Started by Alexander Kim 9 years ago · 2 replies · 781 views
9 years ago

How can i get certain page childrens in a partial template?

Tried:

TWIG
{% for p in page.find('/videos').children if p != page %}
    <article class="video">
        <a href="/" class="d-block mb-3">
            <img src="{{ url('theme://images/dummy.jpg') }}" alt="..." class="img-responsive w-100 rounded">
        </a>
        <a href="/" class="d-block border-bottom">
            <p class="h6">{{ p.title }}</p>
        </a>
    </article>
{% endfor %}

But it didn't work.

9 years ago

Have you tried:
{% set options = { items: {'@page.children': '/my/pages'}, 'limit': 5, 'order': {'by': 'date', 'dir': 'desc'}, 'pagination': true } %} {% set my_collection = page.collection(options) %}

This is from the advanced section of the Page Collections documentation.

👍 1
9 years ago Solution

No results. Not getting childrens 😦

UPDATE. Found my own error, i've included that partial in a main template this way:

{% include 'partials/right-block.html.twig' with {'page': page.find('/video')} %}

When i removed "with" part, your code worked. How does page.find() works? In what cases?

last edited 03/28/18 by Alexander Kim

Suggested topics

Topic Participants Replies Views Activity
General · by Andy Miller, 6 days ago
0 108 6 days ago
General · by lynbor, 1 month ago
3 437 2 weeks ago
General · by lynbor, 3 weeks ago
7 557 2 weeks ago
General · by Harry, 2 weeks ago
0 159 2 weeks ago
General · by Old Man Umby, 1 month ago
2 308 3 weeks ago