Distinguishing between frontmatter YAML fields and other DataView fields

Is there a way to extract fields/properties in a page that are not in the frontmatter?
Like inline DataView fields and fields in comments…

The following two examples will display all of the properties of the current page in a table:

let cur_page = dv.current();
let AoA = Object.entries(cur_page)
 	.filter(([key, value]) => key !== "file")
 	.map(([key, value]) => [key, value]);
dv.table(["property", "value"], AoA);

$= let all = dv.current(); delete all.file; dv.table(["Field", "Value"], Object.entries(all))

Can I somehow also filter out from the displayed result the ones in the YAML header somehow?

You also need to be aware of the sanitised key version of fields, like how My someThing:: hi there becomes an additional my-something. You should be able to check which fields have been defined in the frontmatter through file.frontmatter, but you can’t tell for sure if a field has been defined multiple places which values belong where unless you remove any values found through accessing file.frontmatter.

1 Like

Thanks @holroy,
I don’t know js, so I’ll have to play around with how to use this…

Thanks for the tip about sanitized fields, need to dig a little deeper to understand how this works (will post my final solution here once it works).

A couple of follow up questions :slight_smile:

  1. Are sanitized versions of fields implied from dataview or is it a standard concept across Obsidian? (any place in the docs that covers this properly?)
  2. Also, any recommended entry point to learn js oriented on Obsidian libraries?

Thank you!!!

In case anyone else finds this useful, here’s my solution.
This displays the fields in the current page that are not not in the frontmatter.

```dataviewjs
const front_matter_keys = Object.keys(dv.current().file.frontmatter);

let all = dv.current(); 
delete all.file;
all = Object.entries(all) 
	.filter(([key, value]) => !front_matter_keys.includes(key)) 
	.map(([key, value]) => [key, value]);

dv.table(["property", "value"], all);
```

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