de1mat
5/16/2019 - 2:36 AM

Loop over child pages

An example Chapter level template for Grav that generates a collection of all child pages, and outputs a menu of the child pages.

#grav #twig #template

{% extends 'docs.html.twig' %}

{% block content %}
	<div id="chapter">
		<div id="body-inner">

			<h1>{{ page.title }}</h1>

			{{ page.content }}

			{% set options = { items: {'@page.children': page.route}, 'limit': 30, 'order': {'by': 'default', 'dir': 'asc'}, 'pagination': false } %}
			{% set my_collection = page.collection(options) %}

			<div id="chapter-links">
				<p><strong>The following topics are covered in this section:</strong><br>
					{% for p in my_collection %}
					<a href="{{ p.url }}">{{ p.title }}</a><br/>
					{% endfor %}
				</p>
			</div>

		</div>
	</div>
{% endblock %}