Search code examples
twiggrav

how to show a twig collection in grav


My problem is: If I have a page written this way: (saved home.en.md)

title: 'Home'
published: true
metadata:
    keywords: 'home'
taxonomy:
category:        - main
tag: - 'home'
menu: 'Home'
   slug: home
process:
    twig: true
routable: true
cache_enable: true
visible: true
content:
    items: @root
    order:
        by: date
       dir: desc 
    limit: 10
    pagination: true
---
This are all our pages:

how and where do I have to add the twig text?

{% for p in page.collection %}
 <h3> {{ p.title }} </h3>
 {{ p.summary }}
 {% endfor %}

Solution

  • I resolved this by adding

    template: name-of-template
    

    and in my themes folder I added a name-of-template.html.twig :

    {% extends 'partials/base.html.twig' %}
    {% block content %}
    <ul>
    {% for p in page.collection %}
    
        <h3> {{ p.title }} </h3>
        {{ p.summary }} <br>
       <a href="http://example.com{{p.url}}"> {{ p.title }} </a> <br>
       {# could return http://example.com/my-section/my-category/my-blog-post #}
    
    {% endfor %}
    </ul>
    {% endblock %}
    

    I hope this will help someone!