Replace dataviewjs block with the result

Is there any way to update the page to remove the dataviewjs block and replace it with the result of the block ?

I’m doing a lot of network call in my dataviewjs, and I’d like to avoid them once I got the expected result.

Or is there anyway to access some caching system to save the result of those calls ?

you can turn off “automatic view refreshing” in the dataview settings.
sometimes I do want to refresh the results. For this I have the following templater code in a template file:
<%*app.workspace.activeLeaf.rebuildView()%>
(templater plugin required)

I then bind the inserting of that template to a shortcut, and hit that shortcut every time I want to refresh the dataview block.

1 Like

If you want to run something once through dataview, you could also trigger the query from Templater and use the markdown* variants of the display functions. This way you never see the source code again, and it’s fully replaced by its result.

2 Likes

@holroy Hi, do you have an example or some documentation link ?
I’m not that familiar with templater, I thought it was only used with shortcut or new document.
Here I just paste in an existing document.
And whenever I try to use the templater syntax, I only get it as text, nothing happen

If you something like the following in a file, i.e. myAliasesTemplate:

 <%*
const dv = this.app.plugins.plugins["dataview"].api;
const query = 'LIST aliases WHERE aliases LIMIT 5';
const result = await dv.queryMarkdown(query);

if ( result.successful ) {
 tR += result.value
} else {
  tR += "~~~~\n" + result.error + "\n~~~~"
}
%>

Alternatively, you could write the query as:

const query = `
LIST file.mday
LIMIT 10
`

Or if you’re already using dv.table() or similar, then just do that script, and replace the dv.table() with dv.markdownTable() (see Markdown renderers ).

After you’ve written your template goto Settings > Templater > Template Hotkeys, and add your template into a line there, and click the + icon, which opens up the Hotkeys dialog, where you can locate your template and hit another + icon and choose the hotkey combination you’d like to trigger this template.

Instead of the above, you could also if you run your template just every now and then, go to the Command Pallete, and do the Templater: Open Insert Template modal (or choose your template if you added to the previous list).

1 Like

Yeah so that solution can’t work for my need, I use Telegram Sync to past things into a note. Telegram Sync can’t do the shortcuts

You can potentially let Telegram sync insert the template code, and then have a hotkey to trigger the Templater: Replace templates in the active file.

Haaa awesome, that solve my problem ! My template and my custom function work with that ! Thanks a lot !

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.