Insert backlinks or other metadata with templater

Hi,

I try to insert all inlinks to a note (“backlinks”) in a templater template but without succes. (And I would like to similarly be able to extract other metadata from files for other purposes)
By googling and searching through this forum it seems that “this.app.metadataCache” is the way to go.

I am able to insert frontmatter data such as tags or titles from other note with:

<%*
var get_frontmatter = this.app.metadataCache.getFileCache(tp.file.find_tfile("CurrentNoteName"))
_%>
<% get_frontmatter.frontmatter.title %>

… or from current note with:

<%*
var get_frontmatter = this.app.metadataCache.getFileCache(currentFile)
_%>
<% get_frontmatter.frontmatter.title %>

I see the command “const backlinks = this.app.metadataCache.getBacklinksForFile(currentFile)?.data” mentioned in a few forum posts but am unable to use it to insert all inlinks. This only gets an error:

<%*
var get_backlinks = this.app.metadataCache.getBacklinksForFile(currentFile)
_%>
<% get_backlinks %>

Anyone able to point me in the right direction? Appreciated!

Hi, I’m sorry I can’t help, but was wondering if you found a workaround, I am wondering the same as you.

Hi,
No, I still use dataview. Waiting for the function which is in development that hardcodes dataview content into notes.

Hi, I’m not sure if this is what you are looking for, but I use dataview functionality in my templates. Here is an example:

And you can retrieve data from another note like this:

`=[[Note Name]].file.inlinks`

or

`=link("Note Name").file.inlinks`

In some cases I’ve used dataview to get the data within a template, and then use for example dv.markdownList() appended to the tR to make it a static result.

Is that the functionality you’re looking for?

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