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:

  1. We get the TFile of the note that has content we want to pull in. A TFile is an object that contains a bunch of information about a note. It is used all over Obsidian to get information about a given file.
  2. We use the obsidian api to read the contents of the note. This returns a string of all the note's contents
  3. Do something with the string. I'm just slicing off a random substring, but you can get fancy like turn the string into an array and iterate over each line: content.split("\n").forEach(line => new Notice(line))
  4. To output our value from a JS command block you use 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
templater - contents from another note
Interactive graph