I have a template that triggers every time I create a new note:
<%*
const parentFile = tp.file.find_tfile(app.workspace.getLastOpenFiles()[0]);
const parentLink = app.fileManager.generateMarkdownLink(parentFile, tp.file.folder(true));
let frontmatter = app.metadataCache.getFileCache(parentFile)?.frontmatter || ;
// Get the tags and remove ‘moc’ if it exists
let tags = frontmatter[“tags”] || ;
tags = tags.filter(tag => tag !== ‘moc’);
let tags = frontmatter[“related to”];
-%>
tags: “<% tags %>”
related to: “<% parentLink %>”
aliases:
because I want to inherit the related to, and tags section. In addition to the parent link, how would I also add the links from the source note?
holroy
2
To better present code blocks in the forum posts, please use four backticks in front and after your markdown/code block texts:
Here is a repeated version of your template:
<%*
const parentFile = tp.file.find_tfile(app.workspace.getLastOpenFiles()[0]);
const parentLink = app.fileManager.generateMarkdownLink(parentFile, tp.file.folder(true));
let frontmatter = app.metadataCache.getFileCache(parentFile)?.frontmatter || [];
// Get the tags and remove 'moc' if it exists
let tags = frontmatter["tags"] || [];
tags = tags.filter(tag => tag !== 'moc');
let tags = frontmatter["related to"];
-%>
---
tags: "<% tags %>"
related to: "<% parentLink %>"
aliases:
---
because I want to inherit the related to, and tags section. In addition to the parent link, how would I also add the links from the source note?
Why do you use the last opened files to the parent note? And if that’s the parent note, then what do you consider the source note?
Finally, why don’t you use the tp.config.active_file for some of this?