up:: Projects/Templater
Here's how to grab the contents from another note and bring it forward into the current note.
<%*
const file = tp.file.find_tfile("Note Title")
const content = await app.vault.read(file)
// do something with the content
const output = content.substring(0, 10)
tR += output
%>
Broken down:
content.split("\n").forEach(line => new Notice(line))
tR +=
. In this case I'm outputting my random substring.You can use the TFile approach to get other stuff from a note. For example, say I wanted to access the frontmatter in the metadata:
let output = ""
const file = tp.file.find_tfile("Note Title")
const cache = tp.metadataCache.getFileCache(file)
if (cache) {
const frontmatter = cache.frontmatter
output = frontmatter.someKey
}
tR += output
You use these commands by putting them in their own Template Note inside your templater folder. You can call them by running the insert template command or inside a button:
name Grab That Cheese
type append template
action Grab That Cheese Template Note