Inline DQL query that links to a file based on an inline field

What I’m trying to do

Hello everyone! I’m trying to create on-page navigation linking to the next and previous documents based on a provided ID #, not based on the document’s location in the directory nor on its file name.

Each document has an ID assigned to it with an inline numerical field: idNumber:: 0000 This number is not guaranteed to be constant, and I am also wanting to use this in a template, both of which prevent me from using static links here.

For the layout, all of the documents open with a table meant to provide links to the next and previous files:

| Previous Doc | Next Doc |
| :-- | --: |
| #`= this.idNumber - 1` — [[]] | [[]] — #`= this.idNumber + 1` |

I already have the code I need to calculate the +/- incremented field value. From there how can I, using a standard inline DQL query, then grab a link to the file that has that calculated ID?

Would desperately want to avoid using a dataviewjs query for this problem.

Things I have tried

I have successfully written the solution out in a full dataview code block, but am unsure how to translate that to an inline query:

LIST WITHOUT ID
	file.link
WHERE contains(idNumber, (this.idNumber - 1))

I’ve looked everywhere trying to find the right pieces on how to manipulated inline WHERE calls and contains() functions. Can’t seem to find the right combo that I can then apply to this scenario.

I’m sure I’m missing something incredibly simple here, but I’m fairly new to both Obsidian and dataview/DQL, so any insight would be greatly appreciated!

Thanks in advance!

not answering your question but…you could also use quick explorer plugin where you can go to the previous and next file based on the folder the current file sits in

you can add the commands to a toolbar plugin with any icon and voilá

would also eliminate the need to add id’s to each file

Thanks for the info! Like I mentioned this is independent from the directory location, and I’d like for the info to still be apart of the actual file content. Similarly, these IDs are going to be present regardless of the desired functionality. It’s good to know a plugin like that is available though.

ok, my bad not reading properly…

as for your preference for using plain dv queries, you’d be surprised it might even be easier to write dvjs queries… but i also use bot help for that…

No worries!

And yeah no doubt - especially for a lot of the folks here - the DvJS could probably be easier and faster, but just not something that’s really maintainable long term for me personally.

I haven’t solved this yet, but after stepping away from it I did realize I was overthinking parts of it. If I’m rendering to a table I can just use (an improved version of) the code block that I already know works.

TABLE WITHOUT ID

	docID + file.link AS Previous,
	
	file.link + docID AS Next
	
WHERE
	contains(docID, (this.docID - 1))

	OR contains(docID, (this.docID + 1))

Which is great and simpler than I was trying to make it to begin with, but now I have the new problem of it generating both documents in each column. I’d love to find a way to constrain the first column for the previous document and the second column for the next document, like this:

i guess you need to drop the OR and use flatten or group by??

Awesome I was maybe thinking of one of those but wasn’t getting results but if that’s on the right track I’ll keep playing with those two some more and see where I get. Thank you!

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