obsidian-dataview
obsidian-dataview copied to clipboard
Link to header created by dataviewjs
Where is any way to create link to header that was created in dataviewjs? Something like this:
file1.md:
[[file1.md#header]] <- Unable to find section #header in file1.md
``` dataviewjs
dv.header(1,'header')
```
Can you describe the use case with an example?
I have table of all frontmatter keys with number of notes that have it and some additional columns, its something like custom tailored TOC. After that table there is section for every key with additional info like all notes, most used values, etc. I wanna be able to have a link from "TOC" to every section because page becoming too long.
Oh now that I'm reading this again, there isn't really a way to link to headers rendered in DVJS. The reason is that this is a "view" and these don't exist in the file and so can't be linked to. However, blacksmithgu might know of a way to do this since I'm not very familiar with the internals. I imagine a workaround does exist, just that it might not be straightforward.
Meanwhile, I think I don't fully understand the use case. Do you mean to say that you have a TOC defined in the frontmatter and want to use that to generate dynamic links?
Yes and no :-) I create page with info of every frontmatter key of every page in vault and that page have TOC created via dataviewjs.
Maybe code will be more clear:
const fmts = [];
const rows = dv.pages().forEach(note => {
for (const k in note.file.frontmatter) {
if (!fmts[k]) {fmts[k] = []}
fmts[k].push(note.file.link)
}
})
dv.table(['key name', 'count', 'examples'], Object.keys(fmts).map(k => [
k // section link doesn't work here yet dv.sectionLink(dv.current().file.path,k,false,k)
, fmts[k].length
, fmts[k].slice(0, 3)
]));
dv.el('hr', '')
Object.keys(fmts).forEach(k => {
dv.header(2, k);
dv.list(fmts[k]);
})
I see. Fairly certain that this is not doable but I'll let blacksmithgu add color to this.
Dataview headers are not "real" headers and can't be linked to (since they directly render to your view, and are not Markdown).