# Programmatically build TOC

**URL:** <https://talk.observablehq.com/t/programmatically-build-toc/9910>\
**Category:** Help\
**Created:** [October 13, 2024, 5:31pm UTC](https://talk.observablehq.com/t/programmatically-build-toc/9910 "2024-10-13T17:31:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sbarre](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/sbarre/32/8509_2.png) [@sbarre](https://talk.observablehq.com/u/sbarre)\
**Post date:** [October 13, 2024, 5:31pm UTC](https://talk.observablehq.com/t/programmatically-build-toc/9910/1 "2024-10-13T17:31:54Z")

</div>

I’m wondering is it possible to add items to the table of contents programatically, or is it only built from Markdown headers?

I’m doing some looping through data in my page and would like to add a TOC entry for each block, but I haven’t figured out how to do that. Outputting H2s through a template tag doesn’t do it.

---

<div class="post-metadata">

**Author:** ![mbostock](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mbostock/32/9_2.png) [@mbostock](https://talk.observablehq.com/u/mbostock)\
**Post date:** [October 13, 2024, 6:03pm UTC](https://talk.observablehq.com/t/programmatically-build-toc/9910/2 "2024-10-13T18:03:30Z")

</div>

Is this a question about Observable Framework? If so, please ask on our GitHub Discussions. Thank you.
