royhj
June 17, 2024, 7:12pm
1
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?
holroy
June 17, 2024, 7:16pm
2
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
royhj
June 18, 2024, 7:55am
3
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
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?)
Also, any recommended entry point to learn js oriented on Obsidian libraries?
Thank you!!!
royhj
June 21, 2024, 1:23pm
4
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);
```
system
Closed
July 19, 2024, 1:23pm
5
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.