# Creating Automatic Templates -\> Title and TOC

**URL:** <https://forum.obsidian.md/t/creating-automatic-templates-title-and-toc/111219>\
**Category:** Help\
**Tags:** templater, templates\
**Created:** [February 14, 2026, 11:22pm UTC](https://forum.obsidian.md/t/creating-automatic-templates-title-and-toc/111219 "2026-02-14T23:22:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DukeCannon](https://forum.obsidian.md/user_avatar/forum.obsidian.md/dukecannon/32/89555_2.png) [@DukeCannon](https://forum.obsidian.md/u/DukeCannon)\
**Post date:** [February 14, 2026, 11:22pm UTC](https://forum.obsidian.md/t/creating-automatic-templates-title-and-toc/111219/1 "2026-02-14T23:22:31Z")

</div>

I’m trying to create a template that will do two things when creating a new note:

**First:** Add the title of the note based on the the file name when it’s created using:

* * *

\<% tp.file.title %\>.

* * *

**Second:** I’m trying to add a Table of Contents based on headings within the note itself, using the following:

* * *

\<%\*  
let headers = await tp.file.content  
.split(‘\n’) // Split file into lines  
.filter(t =\> t.match(/^#+\s+/)) // Only get headers  
.map(h =\> {  
let header\_level = h.split(’ ‘)[0].match(/#/g).length; // Get header level  
let header\_text = h.substring(h.indexOf(’ ‘) + 1).trim(); // Get header text  
let header\_link = `[[${tp.file.title}#${header_text}|${header_text}]]`; // Create link  
return `${' '.repeat(header_level - 1)}- ${header_link}`; // Format link  
})  
.join(’\n’); // Join all links  
%\>

Table of Contents

\<% headers %\>

* * *

All of the above is in the actual template note, but none of it actually works. I’m new to this whole concept of templater and the automation it can do for you, so perhaps I don’t fully understand how to incorporate this into a template note.

I saw both the automated title and the TOC on a YouTube video, but no real indication of the code behind it.

Any assistance would be greatly appreciated.

thanks!!

---

<div class="post-metadata">

**Author:** ![DukeCannon](https://forum.obsidian.md/user_avatar/forum.obsidian.md/dukecannon/32/89555_2.png) [@DukeCannon](https://forum.obsidian.md/u/DukeCannon)\
**Post date:** [February 17, 2026, 11:54am UTC](https://forum.obsidian.md/t/creating-automatic-templates-title-and-toc/111219/2 "2026-02-17T11:54:29Z")

</div>

This has been resolved as I found the answers I needed: [Table of Contents (Headers) · SilentVoid13/Templater · Discussion #888 · GitHub](https://github.com/SilentVoid13/Templater/discussions/888)

---

<div class="post-metadata">

**Author:** ![system](https://forum.obsidian.md/uploads/default/original/3X/b/e/bec35fbd23ab28909bb6bfe62cb32eb82dd34019.png) [@system](https://forum.obsidian.md/u/system)\
**Post date:** [May 18, 2026, 11:54am UTC](https://forum.obsidian.md/t/creating-automatic-templates-title-and-toc/111219/3 "2026-05-18T11:54:53Z")

</div>

Closed on May 18, 2026, 11:54am UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
