What I’m trying to do
I am trying to make a database to learn language. So currently I want to display into a dataview or dataviewjs query the property values of the note. There are string values, but for one property, i would like the embbed links of block from other notes in this query.
Context
Globally, i have 2 folders : 1 for the “Sources” which contains some textes in the target language, 1 for the vocabulary.
One word can have different pronunciation which changes the meaning and the sources. A word can have many forms
So the properies of the vocabulary note is like that :
- Form:
- 1:
- Pronunciation: (contains a word)
- Meaning: (contains a word or a sentence)
- Sources: (contains links to block)
-2: …
- 1:
Things I have tried
Until now, I have tried 2 different technics :
1 - I put the properties inline
And with a simple dataview query i obtain this :
But the sources according to the meaning is not so easy to read, and i am not sure if it’s “cleaned” to manage properties.
2- the second technic is i put the properties in frontmatter and made a query with dataviewjs
And i used this dataviewjs
// dataviewjs code to display the note "word" with nested properties
const noteName = "那天"; // Replace with your actual note name
const page = dv.page(noteName);
if (page && page.forme) {
// Create an array to hold the rows for the table
const rows = [];
// Iterate through each "forme" son property ("1", "2", etc.)
for (const [formeKey, formeValue] of Object.entries(page.forme)) {
const pinyin = formeValue.Pinyin || "N/A";
const sens = formeValue.Sens || "N/A";
let sourcesContent = "";
if (formeValue.Sources) {
sourcesContent = formeValue.Sources.map(sourceLink => {
const sourcePage = dv.page(sourceLink.path);
if (sourcePage) {
const sourceBlock = sourcePage.blocks[sourceLink.ref];
return sourceBlock ? sourceBlock.text : "Source block not found";
}
return "Source not found";
}).join("<br/>");
}
// Add the row to the array
rows.push([formeKey, pinyin, sens, sourcesContent]);
}
// Render the table
dv.table(["Forme", "Pinyin", "Sens", "Sources"], rows);
} else {
dv.paragraph("Note not found or no 'forme' property available.");
}
The result of the query is better except for the Sources :
It seems it comes from of the Sources because if put the good name and write “sources” in the frontmatter i got this error message :
I am quite new to Obsidian and i don’t know how to code . I hope somebody could help me to solve this problem.
Thank you to have read this big text ! And sorry for my bad english.