Hey all! Trying to create a template where multiple Templater actions build on top of each other. I’m not a skilled hand at JavaScript, so it’s possible this is an easy solution.
Here’s the code I’m trying to get to work, and I’ll explain it below:
---
tags: workorder
site: "[[<%* dv = app.plugins.plugins.dataview.api; let array = await dv.pagePaths('"Sites"'); tR += await tp.system.suggester(array, array, true, "Which site?"); %>]]"
address: "<%* dv = app.plugins.plugins.dataview.api; tR += await dv.page(dv.page(tp.file.path(true)).site).address; %>"
---
I’m creating a “Work Order” note and attempting to attach two metadata values: “site” and “address”.
The “site” metadata is fetched using DataviewJS inside of a Templater action - tp.system.suggester is fed an array of potential sites based on the DataviewJS request, which returns the path of the proper “site” note, which is then linked because of the enclosing double brackets.
The “address” metadata is fetched by referencing the new value associated with “site” on this note, and uses DataviewJS in the Templater action to get the address on that linked note. So for instance, if site: "[[Sites/Liberty Bell.md]]"
, it would find the “address” metadata on the Liberty Bell note and return Philadelphia
.
Both of these lines of code work independent of the other, so if I just have the first one, it’ll return Sites/Liberty Bell.md
no problem. If I have site set to the “Liberty Bell” value already, the address metadata returns “Philadelphia” no problem.
But if I run them both simultaneously, it errors out because it thinks there’s no note listed at the note’s “site” metadata, even though it runs me through the selection process.
Is there a way to make these run in a strict order, such that one fully resolves before the next one begins? Or, if there’s a good way to create just a block of javascript that internally references the site value for the address and then fills everything all at once, that’s great, too. I just don’t know where to start to do multiline outputs for Templater.