[Dataview] Get pages that link to current section

What I’m trying to do

I would like to collect all pages that mention not just this.file.link, but specific heading, like 'this.file.section`. For example:

My Page

Some content, bla-bla-bla

list from "Folder_with_notes" where contains(file.outlinks, *this.heading.link*)

Note from folder

Topic: [[My Page#RequiredSection]]

End of example

As bonus: dataview request that searches for links with no headings or headings not met in file, like

list from "Folder_with_notes" where contains(file.outlinks, this.file.link) *and have no subpath or have subpath not listed in file*)

Things I have tried

Was able to make something with manual heading comparsion:

list from "Folder_with_notes" where any(file.outlinks, (x) => (meta(x).path = this.file.path) and (meta(x).subpath = "RequiredSection"))

and for generic search

list from "Folder_with_notes" where contains(file.outlinks,this.file.link) or any(file.outlinks, (x) => (meta(x).path = this.file.path) and (meta(x).subpath = "Other_notes"))

but that required to change dataview request for every new heading, that’s annoying, would like to have some kind of autodiscovering for current heading

DataviewJS is acceptable, but preferred to have solution with DQL. For now I have almost same system with subtags, but I have no option to jump to My Page or have to duplicate link and tag

1 Like

As far as I know, the section links are only available from list/task items. This does however also mean that you could do a little trickery like having a list item within the section you want to refer to, and then pickup that section link from that item somehow.

Proof of concept:

## My header

- #thisSection

`= meta(filter(this.file.lists, (l) => contains(l.tags, "#thisSection")).header[0]).subpath `

So it’s kind of possible using that trick, but I think for a practical solution I would much rather use an inline field in the query note:

## My header

requiredSection:: My header

WHERE ... (meta(x).subpath = this.requiredSection) ...

Both options are interesting workaround concepts, but I don’t know how the first one will work if every section will have a list item with the same tag and second one looks not really applicable as you probably will rewrite metadata “requiredSection” for page. Probably, you can’t have lots of independent “requiredSection” fields?
It looks like it’s easier to duplicate tag with section and link without section in the note pages I would like to refer.
Anyway, thanks for help!

Both suggestions would indeed require for the field/tag to be unique on the page in question.

I’ve not seen it, nor looked for it, whether dataviewjs has a reference to its own location, and thusly the section. It could be it has that, but I’m not sure. If it had, that could possibly be an option. It’s rather easy to add a little framework around the DQL query, so you wouldn’t need to know javascript to use that option.

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