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
<%*
title = await tp.system.prompt(“Title”) ?? “YOURDEFAULTVALUE”
// do whatever
%>
date: “<% tp.file.creation_date(“dddd Do MMMM YYYY HH:mm”) %>”
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:
<%*
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.
@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.
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
<%*
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]]