Get metadata from a file referenced in metadata

I am trying to create a ‘dynamic’ breadcrumb, using dataview, that will allow me to move back up a related file chain. To do this, I need to use a YAML value in one file to access YAML data in another file.

In my notes, I have YAML metadata defined as:

project: Project A

Project A is a file in my vault, and within the project file, I have YAML as:

department: Department X

I think I have working dataviewjs code, as I can get the correct values displayed in the console, but I can’t seem to get them onto the rendered page. Here is what I have:

let relPage = dv.page(dv.current().project) //get the page array for the referenced project
// console.log(relPage)
let dept = relPage.department //get the value of 'department'
// console.log(dept)

In the page I have tried:

$=dv.current().dept but this dives me no output
=this.dept also gives me no output

I’m probably doing something really silly and obvious, but I can’t see it.

How can I output the value of the dept variable?

Thanks

Hi @gmakstutis ,

I think the problem might be trying to embed a link in the YAML metadata. I wasn’t able to get Dataview to recognize a linked page in the metadata.

However, when I switched to using a Dataview field for the project reference it worked fine. (I put the Project field inside a comment so it would be invisible, but that’s not required.)

1 Like

I find that I can do this inline. This:

$="[["+dv.current().project+"]]" > $="[["+dv.page(dv.current().project).department+"]]"

Gives me:

Project A > Department X

So, I can make it work. But, for ease of reading I’d like to define things in dataviewjs block and then be able to structure my ‘breadcrumbs’ using the variable names.

What I can’t figure out is why I can’t output a variable value defined in a dataviewjs block.

1 Like

Variables in dataviewjs blocks are only evaluated at render time. They’re not saved as static values.

The only values Dataview can see are YAML metadata fields and Dataview fields.

1 Like

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