PHPackages                             goldnead/statamic-toc - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. goldnead/statamic-toc

ActiveStatamic-addon[Parsing &amp; Serialization](/categories/parsing)

goldnead/statamic-toc
=====================

Automatic Table Of Contents Generator for Statamic Bard-Fields.

v1.7(1y ago)212.8k↓18.8%8[5 issues](https://github.com/goldnead/statamic-toc/issues)[4 PRs](https://github.com/goldnead/statamic-toc/pulls)proprietaryPHPPHP ^7.4 | ^8.0 | ^8.1 | ^8.2CI passing

Since Jul 6Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/goldnead/statamic-toc)[ Packagist](https://packagist.org/packages/goldnead/statamic-toc)[ RSS](/packages/goldnead-statamic-toc/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (29)Used By (0)

[![Latest Version](https://camo.githubusercontent.com/c7707f5c795609b16ac9382846436758c097bc79e8e67fc92af1934bbcd18e37/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f676f6c646e6561642f73746174616d69632d746f633f7374796c653d666c61742d737175617265)](https://github.com/goldnead/statamic-toc/releases)[![Statamic v3](https://camo.githubusercontent.com/9b843e4d74a8b62ebcd69188cbb2aca9fbf6a3f116ede3f778b9d1438c11870e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53746174616d69632d332b2d464632363945)](https://camo.githubusercontent.com/9b843e4d74a8b62ebcd69188cbb2aca9fbf6a3f116ede3f778b9d1438c11870e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53746174616d69632d332b2d464632363945)[![workflow](https://github.com/goldnead/statamic-toc/actions/workflows/tests.yaml/badge.svg)](https://github.com/goldnead/statamic-toc/actions/workflows/tests.yaml/badge.svg)

Statamic ToC
============

[](#statamic-toc)

Automatic Table Of Contents for Statamic Bard or Markdown fields or other HTML content

This addon generates a Table-Of-Contents (ToC) for any Bard- or Markdown-Field in Statamic. Just like any Antlers-Tag you can use this addon in your templates with the usual Statamic-Magic Sugar:

```

  Table Of Contents

      {{ toc depth="3" }}

        {{ toc_title }}
        {{ if children }}

          {{ *recursive children* }}

        {{ /if }}

      {{ /toc }}

```

Sweet, isn't it?

Installation
------------

[](#installation)

Install via composer:

```
composer require goldnead/statamic-toc
```

No further Vendor-Publishing or config files are needed.

Usage
-----

[](#usage)

This Addon provides the functionality to automatically generate an array of headings from your bard or markdown field you can iterate over in your antlers templates. Additionally, it ships with a modifier to automatically generate IDs for anchor-links.

### Blueprint setup

[](#blueprint-setup)

Ideally, this addon works out-of-the-box with any bard setup. Behind the scenes it parses the given content for headlines and generates an associative nested (or unnested, see options below) array that you can iterate through. So, no special headline-sets are needed, just the plain ol' default Bard-field can be used:

```
title: test
sections:
  main:
    display: Main
    fields:
      ...
      -
        handle: bard
        field:
          always_show_set_button: false
          buttons:
            - h2
            - h3
            - bold
            - italic
            - unorderedlist
            - orderedlist
            - removeformat
            - quote
            - anchor
            - image
            - table
          toolbar_mode: fixed
          link_noopener: false
          link_noreferrer: false
          target_blank: false
          reading_time: false
          fullscreen: true
          allow_source: true
          enable_input_rules: true
          enable_paste_rules: true
          display: Bard
          type: bard
          icon: bard
          listable: hidden
```

Of course, you can use as many heading-buttons as you like. If you prefer to save your bard-content as HTML, you can safely turn on `save_html: true` in your bard-settings. You can also use this addon with your markdown-fields. Just pass it along to the tag like this:

```
{{ toc content="{markdown}" }}
  ...
{{ /toc }}

```

or

```
{{ toc field="{markdown_fieldname}" }}
  ...
{{ /toc }}

```

### The `toc` Modifier

[](#the-toc-modifier)

Use the modifier in your templates to add IDs to your headings:

```
{{ text | toc }}

```

Then you get something like this:

```
This is an example heading

  Voluptate do ad anim do mollit proident incididunt culpa ex quis aliquip et
  irure Lorem. Voluptate enim cillum do nostrud eiusmod deserunt.

```

!&gt; Note: When headings are duplicated, the ID is suffixed with a number preventing duplicated IDs which would be semantially wrong in HTML.

### The `toc` Tag

[](#the-toc-tag)

You can use the `toc`-Tag like you would use any recursive tag (like the `nav` Tag) in your Antler-Templates:

```

  {{ toc }}

    {{ toc_title }}

    {{ if children }}

      {{ *recursive children* }}

    {{ /if }}

  {{ /toc }}

```

By default, this addon assumes your bard-content lives inside a content-field named `article`. To change that behaviour you can assign the name of the bard field with the parameter `field`:

`{{ toc field="bard" }}`

or alternatively you can pass the bard-content directly to the `content` parameter:

`{{ toc :content="bard" }} or {{ toc content="{bard}" }}`

If you don't want to display your ToC as a nested list you can pass the parameter `is_flat` which flattens your list to one level:

```

  {{ toc is_flat="true" }}

    {{ toc_title }}

  {{ /toc }}

```

### Variables

[](#variables)

Every Item has the following variables at your disposal:

VariableDescription`toc_title` *(string)*The title of the heading (Note: `title` would be more obvious, but this lead to some weird cascade issues.)` toc_id` *(string)*The slugified title to use as anchor-id`id` *(int)*The internal id used to assign children and parents` is_root` *(bool)*A flag to determine if the current heading is at root level`parent` *(int/null)*Id of parent item if current item is a child`has_children` *(bool)*Flag if current item has children`children` *(array)*Contains all the Child-headings`total_children` *(int)*Number of children (only if `has_children` is true)Also, there are the following global variables present inside the `toc` tag:

VariableDescription`total_results` *(int)*The number of total headings including children.`no_results` *(bool)*True if no results are present### Parameters

[](#parameters)

You can control the behaviour with the following tag-parameters:

ParameterDescription(Type) Default`depth`Specifies wich heading-depth the list includes*(int)* `3``is_flat`When true the list will be displayed as a flat array without nested `children`*(boolean)* `false``field`The name of the bard-field.*(string)* `"article"``content`Content of the bard-structure or HTML String*(string/array/null)* `null``from`The starting point from where the list shohuld be outputted*(string)* `h1`License
-------

[](#license)

This is commercial software. To use it in production you need to purchase a license at the [Statamic-Marketplace](https://statamic.com/addons).

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 97.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~70 days

Recently: every ~212 days

Total

20

Last Release

448d ago

PHP version history (3 changes)v1.0.0PHP ^7.3|^8.0

v1.0.10PHP ^7.4 || ^8.0

v1.4PHP ^7.4 | ^8.0 | ^8.1 | ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/85572d690277234a86834808cab169c4900922b4855fe9028426f8350dd74e97?d=identicon)[goldnead](/maintainers/goldnead)

---

Top Contributors

[![goldnead](https://avatars.githubusercontent.com/u/1313348?v=4)](https://github.com/goldnead "goldnead (109 commits)")[![janh-kramer](https://avatars.githubusercontent.com/u/87782824?v=4)](https://github.com/janh-kramer "janh-kramer (3 commits)")

---

Tags

bardmarkdownstatamic-addonstatamic-v3

### Embed Badge

![Health badge](/badges/goldnead-statamic-toc/health.svg)

```
[![Health](https://phpackages.com/badges/goldnead-statamic-toc/health.svg)](https://phpackages.com/packages/goldnead-statamic-toc)
```

###  Alternatives

[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k89.3M627](/packages/jms-serializer-bundle)[hassankhan/config

Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files

97513.5M170](/packages/hassankhan-config)[meyfa/php-svg

Read, edit, write, and render SVG files with PHP

54613.9M42](/packages/meyfa-php-svg)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
