How can I automatically set the Title based on the first line of text in a note

I found a solution to this, but I don’t know how to implement it. Apparently obsidian has provided no way of doing what pretty much ever other note taking app in history has done: create a title based on the first line of text in a note.

Apparently I’m supposed to download the “templater” plugin, and then create a template using the following code:

<%*
  let title = tp.file.title
  if (title.startsWith("Untitled")) {
    title = await tp.system.prompt("Title");
    await tp.file.rename(`${title}`);
  } 
  tR += "---"
%>
tags: Note <%tp.file.creation_date("YYYY")%>
---
# <%* tR += `${title}` %>

<% tp.file.cursor() %>

___

## References:
- 

---
creation date:: [[<%tp.file.creation_date("YYYY-MM-DD")%>]] <%tp.file.creation_date("HH:mm")%>

I downloaded the templater plugin, but I have no idea where to put this code to create a template that will automatically set all new note titles to the first line of text in the note.

Can someone please help me with this?

Thanks,
Adam

1 Like

Hi Adam,

You can paste this snippet into any blank.md file. You may want to create a folder specifically for templates and set the location in Templater settings.

When you’re creating a new note, you can then press Alt+E to paste your template into the same file or Alt+N to create a new note using this template.

What this snippet does is prompt you to name the Title then renames the note with that title.

I hope this helps!

Not quite what you want, but the Obsidian Filename Heading Sync plugin works if the first line is a heading.

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