Search code examples
grav

Page.find() not working in a partial template


Here's partial template:

<a href="{{ url('videos') }}">
    <h6 class="borbottom text-uppercase"><i class="fab fa-youtube"></i> Serke TV</h6>
</a>

{% for p in page.find('/videos').children if p != page %}
  <h3>{{ p.title }}</h3>
{% endfor %}

I have videos route, that displays all his child elements. I want to display all videos (child elements) in a block as partial template, which i certain pages.

However that page.find() nor page.collection('videos') not working for me.


Solution

  • You are using page object which is the current page. So you are looking for videos pages in the current page.

    You need to use pages object to be able to search in all pages. You can see the functions you can use with this object here