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:
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!
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.
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:
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!