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

Problem with page collection headers

Started by Muut Archive 10 years ago · 2 replies · 553 views
10 years ago

Can anyone help me make the page collections work? I can make a page that lists all the children its own folder, but I can't make a page that lists all the files in a different folder.

I'm trying to follow the guidance in http://learn.getgrav.org/content/collections

I have stripped my page files to the bare bones but still can't see the problem. These are the bare bones files:

TXT
1.home
    default.md

03.animalsV1
    ant
        animal.md
    cat
        animal.md
    listthings1.md

04.animalsV2
    listthings2.md

The listthings1.md file has the following headers, and works fine.

YAML
title: animalsV1
content:
     items: @self.children

The associated template listthings1.html.twig produces a list of animals. Fine.

The problem is with the listthings2.md file. It has these headers, and doesn't work:

YAML
title: animalsV2`
content:
    items: 
        '@page': '/03.animalsV1'

The two associated templates are exactly the same except for a diagnostic message to print the name of the template. Here is the listthings2.html.twig template:

TWIG
{% extends 'partials/base.html.twig' %}

{% block content %}
<p>listthings1 template</p>
    {{ page.title}}
    {{ page.content }}
        {% set collection = page.collection() %}
            <ul>
            {% for child in collection %}
                <li><a href="{{ page.url }}/{{ child.slug }}">{{ child.title }} </a></li>
            {% endfor %}
            </ul>
{% endblock %}

I can tell from the diagnostic that the file has been used, but it produces no list of animals.

I have tried some variations in the header, but to no avail.

Presumably I have misunderstood something. Does anyone have a working example of the '@page': 'filename' construction?

Thanks in advance,
Thomas

10 years ago

The @page takes a route (ie, what shows in the URL) not a file path as you have it with the numeric prefix. So probably should be:

YAML
title: animalsV2
content:
    items: 
        '@page': '/animalsV1'

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1359 9 years ago
Archive · by Muut Archive, 9 years ago
2 936 9 years ago
Archive · by Muut Archive, 9 years ago
2 4066 9 years ago
Archive · by Muut Archive, 9 years ago
1 2955 9 years ago
Archive · by Muut Archive, 9 years ago
3 1121 9 years ago