Templater icon indicating copy to clipboard operation
Templater copied to clipboard

Add Dataview to Templater Context If Dataview is Installed

Open blacksmithgu opened this issue 2 years ago • 7 comments

Is your feature request related to a problem? Please describe.

People frequently use Dataview and Templater together, and I often see requests (on Templater) for doing Dataview-like things like "get frontmatter" or "get all files with this tag". I'd like to add a way to easily access the Dataview API in templater scripts if dataview is installed.

Describe the solution you'd like

If Dataview is installed, Templater exposes the Dataview API object in some relatively easy-to-access name (your choice, though dv or something similarly terse would be optimal). I'm fine with this being hardcoded, or you adding some form of extension point somewhere where I can add the API object in a callback in Dataview code (by discovering Templater).

Describe alternatives you've considered

Users can already access dataview somewhat jankily through app.plugins.plugins.dataview.api, though this is not really documented anywhere. A nicer way like dataview or dv or dva or plugins.dataview or something like that would be nice.

Additional context

I am fine implementing this feature myself, just want to figure out how best to do it.

Dataview generally operates over plain JS types so I don't think there will be any big usability problems / API clashes; DataArray types may act a little wierd but they should pretend to be arrays if they are passed to templater functions.

blacksmithgu avatar Aug 26 '21 23:08 blacksmithgu

This will probably help with issues like #344 since Dataview exposes a lot of in-memory metadata which can help with building nice suggesters, static tables, and so on.

blacksmithgu avatar Aug 26 '21 23:08 blacksmithgu

Also helps on the Dataview side for users who want Templater-like static page rendering (which Dataview does not currently support).

blacksmithgu avatar Aug 26 '21 23:08 blacksmithgu

I can heartily support this request! And yes, almost all people I know actually use both Templater and Dataview. And often complain why they "don’t work better together".

Good suggestion @blacksmithgu!

Moonbase59 avatar Aug 26 '21 23:08 Moonbase59

I feel like the responsibility for this should fall on the plugin developers, with some generic way of handling plug-in auto-suggestions for Templater instead.

Krammy avatar Aug 29 '21 20:08 Krammy

I would love this as well. I think there was something about waiting for dataview to release an API?

mayurankv avatar Oct 26 '22 22:10 mayurankv

You can access the global DataviewAPI via DataviewAPI in a script; it only supports render-to-markdown and queries (since templates don't have a visual file to render to).

blacksmithgu avatar Oct 27 '22 19:10 blacksmithgu