Dataview: Use THIS frontmatter variable OR that one

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.

Thanks!

Was able to solve it!

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.

1 Like

Awesome, that’s so much simpler, thanks!!

So, I just realized that unfortunately the default function seems to split frontmatter that includes multiple lines into separate table entries.
E.g.

Entry: book
Definition:
- information
- more information

with default this book then gets two separate entries one which has information as its Definition and one with more information.

So unless you have a fix, I’ll just use my contains solution. Thanks so much though!

Edit: nevermind, this also happens with my version. Anyone have an idea how to solve this?

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?

Before I tried using this OR function they were just all showing up in the same field:

Definition:
information
more information

Is this possible?
I don’t want them split into individual lines.

Thanks!

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.

Which Definition do I replace?

The one on the first line in your query

That’s not making a difference.

This is the whole snippet. Maybe I’m misunderstanding something.

TABLE WITHOUT ID Icon, link(file.link, EntryTitle) AS "Lemma", join(Locale, ", ") AS Language, join(Entry, ", ") AS Definition, join(Origin, ", ") AS Etymology, Added AS "Date Added"
FROM "Lemmata"

SORT file.name asc


FLATTEN choice(contains(file.frontmatter, "Lemma"), Lemma, Name) AS EntryTitle


FLATTEN default(Definition, Noteworthy) as Entry

FLATTEN choice(contains(file.frontmatter, "Etymology"), Etymology, Biography) AS Origin

FLATTEN choice(contains(file.frontmatter, "Language"), Language, Country) AS Locale

FLATTEN choice(contains(file.frontmatter, "Name"), "👤 ", "📙 ") AS Icon

Then you try it in the other location, which should make a difference.

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 :slight_smile: I prefer that over the comma because sometimes my definitions or whatever end it periods and it so this is easier.

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