de1mat
5/17/2019 - 1:48 AM

Table of Contents

A useful Twig template for Grav. Creates a Table of Contents from the headings on the current page (h1, h2, h3...). Requires the Grav page-toc plugin.

#grav #twig #template

{% if page.content and config.get('plugins.page-toc.active') or attribute(page.header, 'page-toc').active %}
{% set table_of_contents = toc(page.content) %}
	{% if table_of_contents is not empty %}
	<div class="page-toc">
	    <h4><i class="fa fa-fw fa-list-alt"></i> Page Outline</h4>
	    {{ table_of_contents }}
	</div>
	{% endif %}
{% endif %}