A templater template that includes a callout that has tp.file.include

What I’m trying to do

To improve the reusability of my templates, I use tp.file.include a lot.

To improve visibility (at least to me personally), I like to use callouts.

What I’d like is a templater template that defines a callout, and the callout content is a call to tp.file.include to get the stuff to include in the callout. This “stuff” is usually a dataview query.

Things I have tried

Here’s as far as I’ve got: a templater template (call it X) that has the form

text...

>[!NOTE]- A title
> <% await tp.file.include("[[a template including a DQL query]]") %>

more text...

What I get when I insert template X into a note, I get something like

>[!NOTE]- A title
> ```dataview
FROM... rest of DQL query
```

While this isn’t really surprising, I’m stumped by how to get the output of tp.file.include to get wrapped with callout syntax.

And, no, I don’t want to use the admonitions plugin that can do callouts as codeblocks.

While someone puts in what they want, may I ask…if you absolutely need to do this manually and want the callout in a particular area of the note?

I am asking because a few months ago I happened on the Virtual Content plugin and with it I can place queries on the bottom of the note (if I choose to do so) and use in my DVJs queries (dv.current()) to refer to the current file and now that it supports Bases, who knows, maybe someone would want to combine Bases with Virtual Content.

My original objective was to remove excessive repetition of bytes in daily note template generated dailies, but once one figures something out, it can lead to other implementations elsewhere in their vault.

Because in the Content text of your rules you can add markdown, you can even embed your queries in callouts.

E.g.:

> [! Info]
> > [!tip]- Backlinks in Order of Last Modified (Desc)
> > ```dataview
> > TABLE
> > FROM [[]]
> > SORT file.mtime desc
> > ```
> 
> > [!warning]+ Matter, Zotero or other stuff to incorporate
> > ```dataviewjs
> > dv.view('Zoterosource_dvview_js_for_default_template')
> > ```

(Templater used to be my go-to plugin for nearly everything, but now in 2025-26 I use it only for file creation. Of course, it doesn’t mean other people should want to ditch its fuller capabilities.)

I appreciate the suggestion. I’ve not heard of the Virtual Content plugin.

I’ll look into it, but based on your description of it, it’s probably not a good fit.

I prefer to avoid dataviewjs whenever possible. And as for the rest of it, I’ve hand woven a few notes with dataview inside a callout, and I find the visual arrangement beneficial to me. The use of tp.file.include seems to be a logical way to insert a DQL query into a callout (or not, depending on use) so that I can reuse the included template in various contexts.

I think it kind of depends on how you format/write the secondary template (the one templater “includes”) :blush:

Maybe one of these 3 could help you out :blush:

Option 1:

Here’s the “main” template (which is pretty much what you have):

A template to include a callout + DQL

text...

> [!NOTE]- A title
> <% await tp.file.include("[[Template - Callout 1]]") %>

more text...

and here’s the Template - Callout 1 which goes with it:

 ```dataview
> TABLE file.ctime
> FROM "Guides"
> ```

Some included text from "Template - Callout 1"

Note the space right before the “opening” backticks of the dataview code block :blush: .

When the “main” template runs, the very top of the “secondary” template will complete what’s already in the “main” one, at the very beginning of the tp.file.include() line (i.e.: > ), and the whole thing should render a DQL within a callout.


Option 2:

Main template:

A template to include a callout + DQL

text...

<% await tp.file.include("[[Template - Callout 2]]") %>

more text...

And the Template - Callout 2 that works with it:

> [!NOTE]- Title
> ```dataview
> TABLE file.ctime
> FROM "Guides"
> ```

Some included text from "Template - Callout 2"

In this one, the whole callout + DQL is inserted in place of the tp.file.include()


Option 3:

Main template again :smile: :

A template to include a callout + DQL

text...

> [!NOTE]- A title
<% await tp.file.include("[[Template - Callout 3]]") %>

more text...

And the Template - Callout 3

> ```dataview
> TABLE file.ctime
> FROM "Guides"
> ```

Some included text from "Template - Callout 3"

This is somewhat an “half and half” :smile:

I hope this helps a little :blush: .

1 Like

I appreciate the suggestions, @Pch.

The problem with all these is that the included template must incorporate some aspects of the callout syntax. This prevents me from using the included template in a callout some of the times, and outside of them other times.

I was hoping there was a solution that was a bit like the Clipper filters, where you just add a |callout to some stuff and it all gets wrapped in a callout after being processed.

C’est la vie.

Thanks everyone!

You can make one reusable template, and change the output slightly where you’re calling it depending on how you want it formatted.

You keep your original template with the dataview query, no changes needed there.

Then whenever you want to use the template in a callout, you call it like this:

text...

>[!NOTE]- A title
> <% (await tp.file.include("[[a template including a DQL query]]")).split("\n").map((line, index) => index === 0 ? line : `> ${line}`).join("\n") %>

more text...

Which will result in:

text...

>[!NOTE]- A title
> ```dataview
> FROM... rest of DQL query
> ```

more text...
3 Likes