Download the PHP package doefom/statamic-table-of-contents without Composer

On this page you can find all versions of the php package doefom/statamic-table-of-contents. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package statamic-table-of-contents

Statamic Table Of Contents

A Statamic addon that generates a table of contents from a bard or markdown field in your antlers templates using a modifiers.

🌟 Features

🛠 How to Install

You can search for this addon in the Tools > Addons section of the Statamic control panel and click install, or run the following command from your project root:

💡 How to Use

The addon provides two modifiers that you can use anywhere in your antlers templates:

  1. toc: Generates the markup for a table of contents from a given bard or markdown field
  2. with_ids: Adds unique IDs to the headings of the rendered html of a given bard or markdown field

If you want to learn more about Statamic modifiers in general, make sure to check out the official documentation: https://statamic.dev/modifiers

Basic Usage

To generate a table of contents that also links to your rendered content, we use both modifiers like this:

Keep in mind that you should always use both modifiers together to ensure that the table of contents links to the correct headings. Using only one of the modifiers will probably not produce the desired results.

Now let's break down the two modifiers.

The toc Modifier

The toc modifier generates a table of contents from a given bard or markdown field.

Signature of the toc Modifier

By default, the toc modifier will generate an unordered table of contents with all heading levels included. However, you may specify which heading levels to include and whether to render the table of contents as an ordered or unordered list.

Specifying a Range of Heading Levels

You can specify a range of heading levels to be represented in the table of contents (by default, all heading levels from h1 to h6 are included):

This will result in a table of contents that only includes h2, h3, and h4 headings.

Rendering as an Ordered List

If you prefer an ordered list instead of an unordered list, you can do this like so:

Note: Make sure to provide min_level and max_level as well if you want to render the table of contents as an ordered list to maintain the correct order of the parameters.

Options

Parameter Description Default
min_level The minimum heading level to include. 1
max_level The maximum heading level to include. 6
ordered Whether to render the table of contents as an ordered list. false

The with_ids Modifier

The with_ids modifier adds unique IDs to each heading of the rendered html of a given bard or markdown field.

Duplicate Headings

It also respects duplicate headings by appending a sequential number to the heading id.

Styling the Table of Contents

There is no built-in way to style the table of contents, and therefore it's totally up to you to style it as you see fit.

Using the Tailwind Typography Plugin

If you use the Tailwind typography plugin somewhere in your project, you could style the table of contents by adding the prose class to a surrounding element:

Applying Individual Styles

Of course, you can also apply individual styles to the table of contents. To do this, you'll probably want to wrap the table of contents in a div as well, apply a class to it, and then style it in your CSS:

Using Custom Layout

The benefit of this addon is that you have two modifiers, one to generate the table of contents and another one to add unique ids to your headings. This allows you to structure your site however you like.

Handling Bard Fields with Custom Sets

If you are using sets in you bard field, you will need to handle things a little differently.

Generating the Table of Contents

You should convert the bard field to HTML first, then decode the HTML entities, and finally apply the toc modifier.

Adding unique IDs to the Headings

When looping through the bard field, you should apply the toc modifier whenever you handle a text node.

In Combination

🛟 Support

This addon is enthusiastically supported because I rely on it myself and I appreciate all feedback for features or issues you encounter using this addon. If you run into any problems, feel free to open an issue on GitHub.


All versions of statamic-table-of-contents with dependencies

PHP Build Version
Package Version
Requires statamic/cms Version ^5.0
ext-dom Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package doefom/statamic-table-of-contents contains the following files

Loading the files please wait ....