Getting dynamic commands to work in the front matter YAML, it seems is either impossible or only inconsistently possible. For example, I have a frontmatter field mdate:
that represents the last-modified date of the document. One might expect the following to work:
<%+ tp.file.last_modified_date() %>
but it doesn’t. I couldn’t seem to get Dataview inline queries to work in the frontmatter section either. A now-closed thread on this forum and others on r/ObsidianMD have been dead-ends if your goal is to dynamically update the frontmatter section of the document.
But, if you are comfortable working in the command-line shell, I wrote up a solution: Using fswatch
to dynamically update Obsidian documents. I have the script that I posted in that article running against my vault and it works beautifully. You’re free to adapt and use it as you like.
I’ve tested it thoroughly on macOS; and I’ve tested bits and pieces of it on a Debian VM. As for Windows, I don’t know since I have no Windows machine to test it.
If someone has a solution that’s internal to Obsidian, I’m all ears, though!
3 Likes
---
<%*
let url;
let isGithub;
let isYoutube;
const kind = await tp.system.suggester(
["Book", "Video", "Article"],
["book", "video", "article"]
);
if (kind === "article" || kind === "video") {
url = await tp.system.prompt("Url");
}
if (url) {
isGithub = /.*github\.com.*/.test(url);
isYoutube = /.*((youtu\.be)|(youtube\.com)).*/.test(url);
}
tR += `kind: ${kind}`;
if (isGithub) {
tR += `\ngithub: true`;
tR += `\nAlias: {{VALUE:TITLE}} (repo)`;
}
if (isYoutube) {
tR += `\nyoutube: true`;
tR += `\nAlias: {{VALUE:TITLE}} (youtube)`;
}
if (kind === "book") {
const year = await tp.system.prompt("Year");
const publisher = await tp.system.prompt("Publisher");
tR += `\nyear: ${year}`;
tR += `\npublisher: ${publisher}`;
tR += `\nAlias: {{VALUE:TITLE}} (book)`;
}
tR += `\nconsumed: false`
%>
---
Here is a frontmatter piece of a template of my using dynamic templater values in frontmatter.
Another little trick I just discovered is using DataViewJS queried data in templater, is letting dataview append its data to the window object and consuming this inside templater.
1 Like
can you explain this?
I also wanted something like
TotalProgress :: (dataviewjs querry which adds progress from some notes) ? is it possible?