Templater Modular Approach (dataview queries in a separate files)

Has someone noted a successful snippet with dataviewjs or arbitrary js injected into a calling template? :slight_smile:

A recall one of the local wizards planned to try a modular take on templates…
That will simplify writing js without all that \n one-liners :slight_smile:

Me personally tried that, however, hit an exception about variable out of the scope.
That might be something evident for js mighty folks, whereas I myself percive tp.include executes js before embedding the results.
Any smart way we can overcome that?

In other words, the truth is out there:

  1. To make templates easy to read… and less escaping with code fencing blocks and carriage return symbols
  2. To re-use popular snippets (like navigation bar for daily notes)
  3. Ideally to have a way to parametrize dataviewjs snippets
    • that might be too much to ask
    • it is seemingly easy to return output into tR var
    • however, it is not so trivial how to push some data from “parent” template, to tune behavior, say, for dataview query string

Currently it is a struggle to put inline strings like that:

const taskPriorityStr =  `TASK \r\nWHERE file.name = "${weekLink}" \r\nWHERE contains(string(section), "Priority") and !completed \r\nGROUP BY "${weekLinkPriority}" as subtitle`;
tR += "```dataview\r\n" + taskPriorityStr + "\r\n```";

The closest I can think of is templater user function, which should be a js / dataviewjs and won’t work with plain queries like that:

WHERE file.name = "${weekLink}" 
WHERE contains(string(section), "Priority") and !completed 
GROUP BY "${weekLinkPriority}" as subtitle