I reckon you’re still wanting to convert your dataview query for a list of links into a note with both the links and contents, so here are two templates which goes toward that goal.
Template to get access to the list of links
<%*
const dv = app.plugins.plugins.dataview.api
const result = await dv.queryMarkdown(`
LIST FROM [[MEMOIRE]]
`)
if (result.successful) {
tR += result.value.split("\n").map(l => l.substring(2)).join("\n")
} else
tR += `~~~\n${ result.error }\n~~~\n`
%>
Instead of going some convoluted way, and copy-pasting stuff, and re-running some template. Let Templater do the whole stuff. This template produces the list of links directly, after querying from. Replace/modify the query to your liking.
Including the content of the link, as well
Taking it one step further, and include the file content (if any) for this list of links:
<%*
const NAME_RE = /\[\[([^|]+)\|.*/
const dv = app.plugins.plugins.dataview.api
const result = await dv.queryMarkdown(`
LIST FROM [[MEMOIRE]]
`)
if (result.successful) {
for (let line of result.value.split("\n")) {
const link = line.substring(2)
tR += link + "\n"
const filematch = link.match(NAME_RE)
if ( filematch )
tR += await tp.file.include( app.vault.getAbstractFileByPath(filematch[1]) )
else
tR += "==No file found=="
tR += "\n"
}
} else
tR += `~~~\n${ result.error }\n~~~\n`
%>
In addition to building the links, we know extract the filename out of the link, and use app.vault.getAbstractFileByPath()
to get a tFile
object, which pass on to tp.file.include()
to get the full content of (including any template expansion).
In case of some simple errors, it’ll produce an error message related to the query going wrong, or if the file is missing. Could possibly also benefit from some try-catch
around the actual file read.
So there you have an option to produce a full page of links and content based off a dataview query. Insert it into a template, and either associate a hotkey to it, or use the templater insert modal to trigger it.
You could potentially replace the query part with something like const result = await dv.query( tp.file.selection() )
, where you then could open a file, insert your query (without the backticks around it, just the LIST ...
part), select it and run the template and get the query replaced with the link and content stuff. This would allow for other queries, and not just this fixed query.
With a little more modification, you could even make it recognise that your selected text is an actual query, trim off the first and last line, and then run it. This would allow for building the query in a new note until you’re satisfied with the query result, and then select the entire query, and run the template to get it replaced by static content of the link and file contents.