Templater icon indicating copy to clipboard operation
Templater copied to clipboard

tp.file.title doesn't get title if templates are included via tp.file.include

Open dredhorse opened this issue 2 years ago • 8 comments

Describe the bug I have a template which renames the title of the note. After that I include a template which adds part of the frontmatter. After that I include a template which adds the last part of the frontmatter and the H1 with tp.file.title The H1 still has the old title. Also I can't retrieve the frontmatter value which I created with this process as a workaround The key title in the frontmatter has the correct value

Expected behavior H1 should have the correct title

Code

Start Template:

<%* title = tp.file.title if (title.startsWith("Untitled")) { const title_prefix = await tp.system.suggester( ["Note", "Person", "Meeting", "Book"], ["", "@", "! ", "{ "], false, "Type of Note" ) var title = await tp.system.prompt("Title") ?? "Untitled"; title = title_prefix + title; } let type = "Note" let tags = "Note" let template = "t_note" -%> <% await tp.file.rename(title) -%> <%tp.file.include("[[i_frontmatter]]")-%> title: <% title %> Type: <% type %> tags: [<% tags %>] <%* let template_file = "[[" + template + "]]"-%> <%tp.file.include(template_file)%>

i_frontmatter

`

UUID: <% tp.date.now("YYYYMMDDHHmmss") %> DateStamp: <% tp.date.now("YYYY-MM-DD") %> publish: false language: de `

t_note

` Status: Seed Aliases: []


<%tp.file.title%>

<%tp.file.cursor(2)%> `

dredhorse avatar May 10 '22 19:05 dredhorse

so this happens even without obsidian-filename-heading-sync. I think I can work around it by declaring the title as a variable and using that further on instead of calling <% tp.file.title %> again and again. I couldn't find a direct way atm to force a reload of the note, so saving, loading, and then progressing with the templates.

dredhorse avatar May 23 '22 10:05 dredhorse

and that doesn't really work. I have a template which calls a template. In that second template I can't use any variables, and of course, loading the frontmatter or getting the title doesn't work either.

dredhorse avatar May 23 '22 20:05 dredhorse

Doesn't work for me as well. It just grabs the initial "Untitled" name and stays like that no matter what.

pjar avatar May 28 '22 19:05 pjar

I also get the same, it's always "Untitled". I use no advanced scripting.

magpie514 avatar May 30 '22 14:05 magpie514

a workaround mentioned somewhere else

https://github.com/SilentVoid13/Templater/issues/522 was a good reference. Seems tp.config.target_file.basename and this.app.workspace.getActiveFile().basename both work better than tp.file.title right now

dredhorse avatar May 30 '22 17:05 dredhorse

I get the name of the template if I use that. :thinking:

magpie514 avatar May 31 '22 12:05 magpie514

I get the name of the template if I use that. 🤔

Which one do you use? It will depend on how you implemented it in your templates. To be honest atm this is just buggy like hell and the workarounds have pros and cons.

As long as the code isn't updated and perhaps some additional needed options implemented we will have to life with it.

dredhorse avatar May 31 '22 13:05 dredhorse

I get the name of the template if I use that. 🤔

Can you create a new help discussion with your specific script? It'll be easier to see what we can to make it work. Thanks

welpdx avatar May 31 '22 16:05 welpdx