statamic / ideas

💡Discussions on ideas and feature requests for Statamic
https://statamic.dev
31 stars 1 forks source link

Bard fieldtype - Generate ID attributes in headings? #946

Closed stephenmeehanuk closed 1 year ago

stephenmeehanuk commented 1 year ago

It'd be useful to have a way to generate ID attributes in bard headings

We can do this to generate a table of contents (found this in the Statamic Discord),

{{ headings = test_bard | raw | bard_items |
where:type:heading }}
<ul>
    {{ headings }}
    <li>
        <a href="#{{ content | bard_text | slugify | safe_truncate:30}}">{{ content | bard_text }}</a>
    </li>
    {{ /headings }}
</ul>

But the anchors don't work, because the headings in the bard fieldtype don't have ID attributes.

Could this option be added to a future release?

jasonvarga commented 1 year ago

Check out https://statamic.com/addons/jacksleight/bard-mutator

One of the examples are how to add ids to headings:

CleanShot 2023-02-02 at 11 46 43