In my dictionary, I’d like to add a template for people. However, I’d like to adapt some of the frontmatter variables in their template, e.g. instead of “Entry”, I’d have “Name”.
However, a) I’d like to list them in the same table as everything else, and b) I’d like to avoid having to add another variable, e.g. Type, etc.
This is my dictionary DV table, with the last line being my attempt at solving this.
TABLE WITHOUT ID EntryTitle as Entry, Language, Definition, Etymology, Added AS "Date Added"
FROM "Entries"
SORT Enry asc
FLATTEN choice(contains(file, "Name:"), Name, Entry) AS EntryTitle
I can’t figure out how to implement the OR part of this. I know that file refers to the title, but I can’t find the object that refers to the frontmatter.
TABLE WITHOUT ID Icon, link(file.link, EntryTitle) AS Entry, Locale AS Language, Entry AS Definition, Origin AS Etymology, Added AS "Date Added"
FROM "Entries"
SORT EntryTitle asc
FLATTEN choice(contains(file.frontmatter, "Name"), Name, Entry) AS EntryTitle
I hadn’t seen the object file.frontmatter before.
That does what I wanted. It checks to see if there’s ‘Name’ as a frontmatter key, otherwise uses ‘Entry’. Also, the contains query can’t have a : colon in it, otherwise it won’t work.
In some circumstances you could possibly use FLATTEN default(Name, Entry) as EntryTitle, which if I remember correctly would try to use the field Name firstly, and if that is null or not defined it would try using Entry.
To split a list into its separate entries one would normally use FLATTEN, but I’m not sure that’s what you’d want in this case. How would you distinguish which definition to use?
You could possibly join the entries? Or use the first?
Try replacing Definition, with join(Definition, ", ") as Definition. This would join multiple definitions together with ", " between items. You could of course replace that with something else.
OK, now I think it works! But default makes it not work. Not sure why. This is my snippet now.
TABLE WITHOUT ID link(file.link, EntryTitle) AS "Lemma", Icon, Locale AS Language, MainPart AS Definition, Origin AS Etymology, Added AS "Date Added"
FROM "Lemmata"
SORT file.name asc
FLATTEN choice(econtains(file.frontmatter, "Lemma"), Lemma, Name) AS EntryTitle
FLATTEN choice(econtains(file.frontmatter, "Definition"), join(Definition, " "), join(Noteworthy, " ")) AS MainPart
FLATTEN choice(econtains(file.frontmatter, "Etymology"), join(Etymology, " "), join(Biography, " ")) AS Origin
FLATTEN choice(econtains(file.frontmatter, "Language"), join(Language, " "), join(Country, " ")) AS Locale
FLATTEN choice(econtains(file.frontmatter, "Name"), "👤 ", "📙 ") AS Icon
I replaced the comma in join with a next line symbol. This works I prefer that over the comma because sometimes my definitions or whatever end it periods and it so this is easier.