Hi! I’m setting up a bookshelf of sorts that has various metadata in the frontmatter which I am summarizing in a callout in the body of the note itself. What I’d like to do is hide a certain keyword in the summary callout when it’s empty in the frontmatter. I am an absolute beginner with Javascript AND Obsidian, and I’m hoping this is just a dead simple thing someone can give me a hand with. What I’ve got so far is copy/pasted from @Gibson 's wonderfully inspiring Bookshelf setup.
Things I have tried
The book note template looks like this:
---
cssclass: bookentry
Author:
Status:
Format:
Location:
Genre:
SeriesName:
SeriesNumber:
---
>[!Metadata]
>**Author:** `= this.Author`
>**Status:** `= this.Status`
>**Format:** `= this.Format`
>**Location:** `= this.Location`
>**Genre:** `= this.Genre`
>**Series:** `= this.SeriesName` : Book `= this.SeriesNumber`
I’ve tried various phrasings of if statements to try to only output that last line if SeriesName has a value, but I haven’t been able to get the grammar right. I tried looking through Substack, but I’m just not super clear on how to translate general JS grammar into something inline that Obsidian understands.
What I’m trying to do
What I really want is for the final “Series” line in the callout/summary to only appear if there is data for the “SeriesName”. I’m just not sure how to make it happen!
Here’s what it looks like for a book in a series:
And here’s what it currently looks like for a book not in a series:
And here’s what I’d like it to look like for a book not in a series:
I could also totally live with this if the “Series:” pair in the callout summary is just blank (or has the autogenerated dash). (So the colon and “Book” word and and SeriesNumber didn’t appear if there is no SeriesName.)
Thanks so much!