Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

Filter out headers from a table of contents

Started by Sean McDaniel 6 years ago · 0 replies · 390 views
6 years ago

Dear community,

I'm have some inline TWIG code on one of my markdown webpages to print a table of contents exactly where I want it (instead of using the default plugin option). It works great, but it includes some headers that I'd like to filter out.

TWIG
{% set table_of_contents = toc(page.content, 2, 4) %}
{{ table_of_contents }}

I can't filter out the headers through choice of included header level because that removes headers I want. I'd like to filter by string. Let's say there are two headers I'd like to filter out "Header 1" and "Header 2". How would I adapt the above code to remove those headers? I looked up filters in GRAV documentation but I didn't seem to find one that would suit my needs.

Thank you,

Sean

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 80 9 hours ago
General · by pamtbaau, 14 hours ago
1 51 13 hours ago
General · by Andy Miller, 1 day ago
0 44 1 day ago
General · by Marcel, 12 months ago
6 346 5 days ago
General · by Duc , 5 days ago
3 40 5 days ago