Accessing file headings as a variable in dataview

This question has come up quite a few times on the forum in the past few days! dataview works on Field:: value pairs. Some fields like file.day and file.tasks are “implicit”, so you do not need to write them down anywhere in your file to use them, but for anything that is not on the “implicit field” list in the documentation, you cannot access it without a Field_name:: Field_value annotation. Headings and other text content of your file are not on the implicit list.

Possible alternatives:

  • if your files have only one level 2 heading, you could use Obsidian’s built-in search via an embedded query block. There is a query operator for tags that can filter for my-tag and I think you can use a regular expression (regex) for “line that starts with exactly ## and then a space” to get the level 2 heading. Pinging @I-d-as or some other regex expert on the forum for how to translate that last bit from English into a regex. Hopefully one of them can share how to display the text under that heading in the query results.
  • Call your level 2 heading the same thing every time and use ![[otherNote#lvl2HeadingName]] embedding to display the section.
  • Save the name of your level2Heading in some dataview variable (for example myHeading:: and then use a LIST or TABLE dataview to embed(link("pathToOtherFile#" + myHeading)) embed the section as in the option above. There is a note on the dataview page that embed may not display consistently, so if you have issues you will have to try some other tactic.
  • Maybe there is a different community plugin that can do this?

Good luck!

1 Like