Dataviewjs relative `` for MetaData Menu

I’m continuing to stumble on dataviewjs to correctly create “a javascript function returning an array of string” for a query to create a field in MetaData Menu. Thank you already to @Anwen and @holroy for help on a related question #75409.

For this example, I have a folder of books and would like to get links to all books of a specific genre (e.g., comedy). I have this working but returning absolute/long links, i.e. "[[books/happy|happy story]]". I would like to have the relative/short links, i.e., "[[happy story]]".

Here is what I have:
dv.pages('"books"').where(p => p.genre == "comedy")

I also tried the following which didn’t work at all:
dv.fileLink('"human-beans"').where(p => p.realm == "health-medical")

Thank you for your help.

I think this gives you what you’re looking for:

dv.pages('"books"').where(p => p.genre == "comedy").map(p =>  "[[" + + "]]")

I am realizing now that I was using the wrong MetaData Menu field and should be using file rather than select. So while @Anwen’s solution works beautifully with select, I can more efficiently use the file MetaData Menu field with the following query: dv.pages('"books"').where(p => p.genre == "comedy").

1 Like

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