Dataview dv.pages() for pages of all incoming links

Hi there, I’ve got a question on dataview in combination with the Metadata Menu plugin.

What I’m trying to do

In the Metadata Menu plugin, I’m trying to create a multifile class which contains all incoming links to that file and allows me to choose from them. For this I need a dataviewJS query based around dv.pages(), since that is all that metadata menu allows as an acceptable query. Looking at similar questions online, the answer is often dv.current().file.inlinks, which usually would work swimmingly, but is not accepted by the metadata menu plugin. It has to be dv.pages(). Moreover, the output cannot be adjusted into a different data type, since metadata menu expects a dv.pages() output, meaning that any functions afterwards are only allowed to limit the search rather than change it. E.g. .map, .limit and .where are all allowed, but .inlinks is not, since that changes the output.

Things I have tried

I have tried all I can myself but am completely stumped. I have asked in the Obsidian discord under the dataview channel, but since I have some difficulty explaining myself given my limited dataview/programming knowledge and English not being my first language, it was difficult for them to help me. I am therefore asking here in the hopes of getting an answer that way.

I hope it is somewhat clear what I am trying to achieve.

Thanks in advance!

Quick update: with some help from the discord I was able to get a whole lot closer, coming to the following query: $= dv.pages().filter(p => => l.path).includes(current.file.path))

Metadata menu accepts this but starts behaving weirdly, signaling missing values and getting stuck in a loop. Moreover, when I enter the query outside of metadata menu, I get the following syntax reference error: current is not defined

Has anyone got an idea how to deal with this?

Have you tried:

dv.pages(`"${ dv.current().file.path }"`).file.inlinks

Thanks for the reply! Unfortunately this does not seem to work. This is probably beacuse metadata menu expects a dv.pages() output and not an actual link. I also tried the method of referencing the current file you describe in the query I commented earlier (i.e. dv.pages().filter(p => => l.path).includes(`"${dv.current().file.path}"`)), but this does not work either

OK, what does the plugin say about either of these variants:

dv.pages(`"${ dv.current().file.path }"`) => 
dv.current() =>

The output of either of these should be of the same type as a pure dv.pages() output.

What type of field are you trying to do this in? A “Lookup” or a “File”?

If I defined a field of type “File”, I can simply use “current.file.inlinks” to get the inlinks of the current file.

If your field type is “Lookup” I’m not sure how that behaves…

So, I’d always tried .current(), in other words, with the parentheses, because that’s how I’d always see people use it. But this is the answer! current.file.inlinks works like a charm. Thank you so much for your help!

Normally you’d need to use dv.current(), but this plugin has made current available in some of its contexts.

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