Setting Up A Template

Things I have tried

Looking through the forums… github forum :frowning:

Hi, can I get a hand w/ setting up a basic template so that when I create a new note (untitled) it prompts for a title. Below is the code I’ve control copied from the forum (apologize that I can’t recall the original author but I’ve been zipping back and forth trying to find a solution). I have templater but this just copies the text instead of running the code? I believe I have all my opening/closing brackets in order?

What gives :frowning:


<%*
title = await tp.system.prompt(“Title”) ?? “YOURDEFAULTVALUE”
// do whatever
%>

date: “<% tp.file.creation_date(“dddd Do MMMM YYYY HH:mm”) %>”

Topic: <% tp.file.cursor(1) %>

Source:
Linked Files:

Tags:

What I’m trying to do

It was your quotes, they are smart quotes I think instead of straight quotes.

<%*
title = await tp.system.prompt(“Title”) ?? “YOURDEFAULTVALUE”
// do whatever
%>

date: “<% tp.file.creation_date(“dddd Do MMMM YYYY HH:mm”) %>"

Topic: <% tp.file.cursor(1) %>

Source:
Linked Files:

I think they even changed here when I posted. But if you change them in the Obsidian editor they should be straight quotes.

Actually, that is just Discourse rendering them, since it wasn’t put in a code block. 3trees did type plain quotes.

@3trees on this forum, please try to format your code inside a code block, or between triple backticks. It will make it easier to read for us. Like this:

```
Code here
```

Shoot I see; unfortunately I can’t seem to edit my original post.

Do I just need to change “<%*” to ‘’’ to make the code work in Obsidian?

Again, please use code blocks to make your question clear. You can post it again in a reply.

here bud


<%*
  let title = tp.file.title
  if (title.startsWith("Untitled")) {
    title = await tp.system.prompt("Title");
    await tp.file.rename(title);
  } 
  tR += "---"
%>

Put that in a template note - and it’ll prompt with a box to type the title, it if it’s “Untitled”.

So it won’t run if you say in a note, create a new note by typing [[new note]] and then clicking it, well that wouldn’t be “Untitled” so will not run.

Hope that helps in understanding how it actually works.

1 Like

Many thanks it’s working now! Happy holidays to everyone here.

1 Like

@3trees Ah glad it works, BTW, if you want YAML to also automatically be added, you can just Type out the YAML like normal right below with the line breaks etc. (of course without adding more javascript this would have to be static)

i’ll do that and just set up the YAML and then with a cursor positioning code snippet (option tab) takes me directly to them once the note is created.

@3trees

I figured I would just provide you with my full template, as you will easily be able to see what it does and modify it to your liking - it was my intention in design :grimacing:


<%*
  let title = tp.file.title
  if (title.startsWith("Untitled")) {
    title = await tp.system.prompt("Title");
    await tp.file.rename(title);
  } 
  tR += "---"
%>
Title:  <%* tR += title %>
Tags: dailynote/2021, daily, journal
---
# <%* tR += title %>
<< [[<% tp.date.now("YYYY-MM-DD", -1, tp.file.title, "YYYY-MM-DD") %>]] | [[<% tp.date.now("YYYY-MM-DD", 1, tp.file.title, "YYYY-MM-DD") %>]] >> 

###### Recent Notes
```dataview 
TABLE file.ctime as created, file.mtime as mod, file.path as Path
from ""
WHERE file.mday >= date(today)
SORT file.mtime desc
Start of Day
  • [ ] OmniFocus Morning Routine
  • [ ] Check Email
  • [ ] Check Calendar ~ Time Block
End of Day
  • [ ] Daily Reflection [[<%* tR += title %> Reflections]]
  • [ ] Sweep OmniFocus

![[<% tp.date.now(“YYYY-MM-DD”, -1, tp.file.title, “YYYY-MM-DD”) %> Reflections]]


I can’t attach screenshots for some reason, I’m a functioning moron so someone can yell at me how to do it - I learn well that way.
1 Like

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