Query that excludes links in another page (aka dataview's 'outgoing' rule)

I have a list for films that Terry and Lucie might like (“Terry Lucie”).
I have another list of films they have already seen (“Terry Lucie Saw”).
When they come over for the weekly film night, I choose from the first list, which excludes everything in the 2nd list. Works great but for one thing: when I open the md file directly through Win Explorer, instead of seeing a list of films that I can choose from, I see the dataview rules:

table from #filmtitle and !outgoing([[Terry Lucie Saw]])
where contains(lists, "Terry") or contains(lists, "Lucie")
sort file.name

So I decided to use Obsidian query instead, so that I could copy paste the results, and just redo the query before they came over just to update it. But…

:question:I don’t know how to add the “and !outgoing([[Terry Lucie Saw]])” part into this query:

tag: #filmtitle (line: (lists Terry) OR line: (lists Lucie))

… and the file is not a link in the Terry Lucie Saw page.

Is it possible with Obsidian search (aka query) or must I stick with Dataview and just deal with the fact that many of my md files will be useless when opened via explorer.

you could export a dataview table as csv with the “table to csv exporter” plugin, or, if you want to get really advanced, it’s possible to use templater to bake out the results of a dataview or dataviewjs query, though it’s on the advanced side of things.

cheezopath, it’s actually what I do now. I use templater to call a template that includes dataviewAPI calls, and it ‘prints’ the results directly in my page. Ideal but for having to create so many specific templates everywhere…

is it possible to pass a generic templater user function a dataview query string to execute inside, then put that template on a hotkey?

That’s the question.

I think I got this working.

First in your frontmatter, add a dataview query string, eg:

---
query: 'LIST LIMIT 3'
---

make dvbake.js in your templater scripts folder:

async function bake (tp,qstring) {
    const query = await app.plugins.plugins.dataview.api.queryMarkdown(qstring)
    console.log(query.value)
    let result = query.value
    return result
}
module.exports = bake;

Then you can use this templater code:

<% tp.user.dvbake(tp,tp.frontmatter["query"]) %>

Which you can bind to a key. Now any time you hit that key, if the note you’re on has query in the yaml, it’ll bake out the dataview as markdown.

EDIT: I guess tp.frontmatter is already being passed in via tp… well anyway you get the idea, you can simplify it

1 Like

@cheezopath I am so sorry for the delay in getting back to you.
I was finally able to get back to this, and I cannot thank you enough! It works like a charm.

I’m a little concerned about having queries in frontmatter, especially really complicated ones, but maybe I can now simplify my more complicated ones, given this new trick!

Thank you SO much. You have no idea how useful this is to me.

1 Like

you’re welcome! I was just as chuffed when I worked it out.

You know what would also be cool?

---
template: [[link to template]]
---

A general shortcut to a script that says: apply the template value to this page.

(for those templates that are too complicated to fit in yaml as values).

can you give an example use case? Is this something templater/quickadd/buttons could do?

Here’s an example. In my movie database I keep lists for each of my favourite directors.
The list includes the films of theirs that I own, grouped into “seen” and “not seen”.
The output is markdown, so the template uses templater.

In the screenshot, the template is on the left. As you can see, it is much too lengthy and complicated to be put into a frontmatter value field.

#1 in the picture is a comment that reminds me how to update this page; it says to delete everything except frontmatter, and then call the [[MD Update Director's Page]] template

#2 But wouldn’t it be cool if I had a frontmatter field called template, whose value was a link to the template to be used to update this page? Then whenever I had to update I could just go to the page and hit Alt+D, a shortcut to a different template that just says: apply <%tp.frontmatter.template %> to this page below the frontmatter.

I think you should be able to accomplish this with the button plugin – it can trigger templates and handle deleting lines I believe

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