A composition from YAML fields (dataview)

I have this fields in YAML front matter of a note a.md

---

Klasse: HH23A
Fach: IW

---

The problem

Is there a way to reach the same as when I use this?

=[[HH23A IW]].Klassenlehrer


I tried these, which do not work.

=this.Klasse + " " + this.Fach + ".Klassenlehrer"

="[[" + this.Klasse + " " + this.Fach + "]]" + "." + Klassenlehrer

image


This works (“Klassenlehrer” holds text), but I want to assemble the given fields from the YAML in note A.md.

=[[HH23A IW]].Klassenlehrer


No, I don't want to add the field Klassenlehrer redundantly to the YAML of note a.md ;-)

An other solution, but its also redundant:

---
Klasse: HH23A
Fach: IW
KlasseFach: "[[HH23A IW]]"
---

=this.Klassefach.Klassenlehrer


How can I get a solution without redundancy?

Do either of these work?

`="[["+this.Klasse+" "+this.Fach+"]]"+"."+"Klassenlehrer"`

`="[[" + this.Klasse + " " + this.Fach + "]]" + "." + "Klassenlehrer"`

No, the result looks as so:

Hi.

What result do you expect to see? What is Klassenlehrer and where is it stored? Possible to share a full sample of metadata?

I expect to see the value of the field Klassenlehrer. This is a text like this:

---
Klassenlehrer: "Mr. Miller and Mrs. Smith"

---

This value comes from the shown YAML of the note [[HH23A IW]].

Klasse: class
Fach: subject
Klassenlehrer: class teacher; heads of the class

You can achieve your goals if you use link() to build the composition link first, and then extract the Klassenlehrer from that link.

Composition link: `= link(this.Klasse + " " + this.Fach) `

Field from link: `= link(this.Klasse + " " + this.Fach).Klassenlehrer `

You only need the last variant, the first is just to show the result of the link composition.


A caveat with this approach is related to what happens if you change the class name or subject name. Either you’ll need to remember to update all the Klasse fields and/or Fach fields, or you’ll need to remember to change the corresponding notes, i.e. HH23A IW, at the same times. Without fully knowing your context, you might be better of defining the class link completely like in:

KlasseLink: "[[HH23A IW]]"

If you now rename the note the links will be updated, and you can still don’t have any redudancy but you do need to split the link into Klasse and Fach if you need those bits. This will also make getting the teacher slightly easier, as you now could do: this.KlasseLink.KlassenLehrer.

1 Like

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