Updating dataview and tasks queries across multiple notes that reference the notes title

I have several dozen “area” and “project” notes that include dataview and tasks queries. These queries reference the current note’s title using this.file.name or this.file.link, to show context-specific results — like tasks or notes associated with that area or project.

Here are simplified examples of the kinds of queries I’m using:

[filter by function (task.file.property('area') || "").includes("[[" + query.file.filenameWithoutExtension + "]]");]
list
where (contains(area, this.file.name) OR contains(area, this.file.link))

These queries are always placed near the top of the note, using the same structure in every file. I use Templater to insert them when creating a new note.

The problem is: when I need to change the logic of these queries — for example, to refine a filter — I have to manually update every single note. Since the queries depend on the file title, I can’t just transclude a shared partial; the context (this.file) becomes that of the partial, not the host note, and the queries break.

I’m looking for a way to avoid editing each note individually when I want to update these query blocks. This could be a Templater-based solution, a plugin, a batch-editing method, or something else. I’m also open to using JavaScript, regex, or external tools if needed.

If anyone has solved a similar problem, I’d really appreciate hearing how you approached it.

Thanks.

Hello!
To avoid manually updating Dataview queries in dozens of Obsidian “area” and “project” notes that reference the current file’s title, the best approach is likely using Templater Script Functions. Create a JavaScript function within Templater that dynamically generates the Dataview query string using tp.file.title or tp.file.name. Then, embed this function call in your note templates instead of the static query block. When you need to update the query logic, you only edit the script function, and the changes will apply to all notes using it when they are re-rendered. Other options like Templater snippets, community plugins, external scripting, or careful batch editing with regex are also possibilities, but script functions offer a clean and Obsidian-native solution.

Some other options depending on your extended use case would be to either include a note with the generic queries, or to use dv.view() in the note and key that refer to the query. This would allow for you to update the query whenever you want, and any note using that view would use the updated query immediately.

On a slight stud note, sone of us are also contemplating on how to use stuff like the Note toolbar plugin, and something like the Contextual Sidecar plugin, to avoid having anything in the note itself, and rather have either a toolbar or updated sidebar panel presenting the needed/wanted queries. See thread below of that’s interesting.

Had exactly the same problem, and I achieve what you’re trying to do with this piece of dataviewjs in the note:

```dataviewjs
dv.paragraph(await dv.io.load("_inserts/header-people.md"))
```

I have a Templater template for People notes, Project notes, Day notes, etc each with the same code and a different “insert” file. For example, the above “insert” note is:

> [!todo]+ Open tasks
> ```dataview
> task 
> where (contains(outlinks, [[]]) OR contains(path, this.file.name) ) AND status = " "
> ```

> [!done]- Completed tasks
> ```dataview
> task 
> where (contains(outlinks, [[]]) OR contains(path, this.file.name) ) AND completed
> sort desc
> ```

Which gives me this at the top of every person note:


(have used a note that doesn’t have private information present, but those queries give me the currently open tasks and the previously completed tasks for that person from across the whole vault. So when I’m having a 121 or talk with someone, I just open their note and I can see all the tasks that are currently on their plate. Very useful)

Once that’s in place, then updating the relevant insert file updates what is present in all of the People/Project/etc notes :tada:

PS: technically, doing this with dv.span adds block elements inside a span element, which goes against the HTML spec - but it works, and I’ll never had an issues with formatting, layout, exporting, anything (even with my more complicated inserts). You can use dv. paragraph as well, but that also inserts a horizontal scrollbar which I find annoying - hence my use of dv.span

PPS: just for clarity, the query you write uses the file that it’s embedded in for it’s context - so for example contains(path, this.file.name) will find tasks that are present in the note the insert is embedded in, not the insert file itself. Most of my queries are some variation of “links to this file” like your examples, so I think this should probably Just Work™ for you.

PPPS: you can also do this in other ways by directly embedding dataviewjs queries from a file, rather than inserting another .md file but for my uses I’ve found using this approach with the insert file as a .md file works best - means I can add multiple queries and do things like wrapping in callouts/headings, add formatting or static text reminders, etc.