Hi,
is use this statement
dv.el("i",dv.current().file.frontmatter);
and the result is a list:
is it possible to get the same as table like this
fields |
values |
field1 |
value1 |
|
value2 |
field2 |
value3 |
|
value4 |
thanks in advance
I found this on the net (I apologize to original author) and use it. Note this uses the amazing dataview plugin.
I save the javascript in a file Assets/Scripts/embedded_properties.js
:
let frontmatter = dv.current().file.frontmatter;
// Define fields to exclude (adapt as necessary)
let excludeFields = ['date created', 'MOCs', 'tags', 'url']
// Extract and filter the keys and values based on the exclusion list
let filtered_keys = Object.keys(frontmatter).filter(key => ! excludeFields.includes(key));
let filtered_values = filtered_keys.map(key => frontmatter[key]);
// Define an array to hold each row of the table
let rows = [];
// Populate the rows array with key-value pairs
for (let i = 0; i < filtered_keys.length; i++) {
// Convert array values (e.g. tags) to a single string separated by commas
let value = Array.isArray(filtered_values[i]) ? filtered_values[i].join(', ') : filtered_values [i];
if (filtered_keys[i] === 'date modified') {
value = "[[" + filtered_values[i] + "]]";
}
let key = "<span style='display:flex; color: #2d82cd; justify-content: right;'>" + filtered_keys[i] + ":</cspan>";
rows.push([key, value])
}
// Generate a table with two columns and populate with rows
dv.table(['', ''], rows)
Then where I want the properties to be displayed:
```dataviewjs
const data = await dv.io.load("Assets/Scripts/embedded_properties.js");
dv.executeJs(data);
```
2 Likes
That works, thanks.
I changed the ",
" to β<br>
β to get multiple values ββin a key in the table column below each other.
// let value = Array.isArray(filtered_values[i]) ? filtered_values[i].join(', ') : filtered_values [i];
let value = Array.isArray(filtered_values[i]) ? filtered_values[i].join('<br>') : filtered_values [i];