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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

Get page collection in a partial template

Solved by Alexander Kim View solution

Started by Alexander Kim 8 years ago · 2 replies · 577 views
8 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.

8 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
8 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 Jerry Hunt, 4 days ago
2 82 12 hours ago
General · by pamtbaau, 17 hours ago
1 55 16 hours ago
General · by Andy Miller, 1 day ago
0 45 1 day ago
General · by Marcel, 12 months ago
6 348 5 days ago
General · by Duc , 5 days ago
3 43 5 days ago