Template code working only half of the time

I found this very cool piece of code to create templates for recording quotes. Unfortunately, it works half of the time. What am I doing wrong?

TEMPLATE:


tags: type/quote
aliases:
quote:
author:
reference:
year:
source:
source-link:
featured:


{{Title}}

[!QUOTE]
= this.quote
= this.author, = this.reference

Source

  • = this.source, = this.source-link

QUOTE FILE WHERE IT WORKS VERY WELL

tags: type/quote
aliases:
quote: “If anyone can prove and show to me that I think and act in error, I will gladly change it—for I seek the truth, by which no one has ever been harmed. The one who is harmed is the one who abides in deceit and ignorance.”
author: [[Marcus Aurelius]]
reference: [[Meditations, 6.21]]
year:
source: [[The Daily Stoic]]
source-link: [[The Daily Stoic#Chapter 117 April 25. There’s Nothing Wrong with Being Wrong]]
featured:


Marcus Aurelius on accepting an error

[!QUOTE]
= this.quote
= this.author, = this.reference

^bd1e85

Source

  • = this.source, = this.source-link

QUOTE FILE WHERE IT DOESN’T WORK:


tags: type/quote, #4family
aliases:
quote: “Every person you meet knows something you don’t; learn from them.”
author: [[H. Jackson Brown]]
reference:
year:
source: [[the Daily Quote app]]
source-link: ‎Daily Quote - Positive quotes on the App Store
featured:


H. Jackson Brown on learning from every person you meet

[!QUOTE]
= this.quote
= this.author, = this.reference

^12b8c4

Source

  • = this.source, = this.source-link

Please advise what am I doing wrong?

What do you mean by “doesn’t work” and “half of the time”?
(I mean, that’s a bit vague :sweat_smile: )

How do you apply the template ? What plugin(s) do you use ?
(I guessed Dataview was involved :innocent: )

From my side of the screen, considering you aren’t sharing the results as raw markdown (within a codeblock… in the same way as you would do it in Obsidian), it’s a bit difficult to guide you :no_mouth:

I had to improvise and correct some things in the YAML (as I use Properties some values were invalid, as not correctly formatted) but copying/pasting this in Obsidian, seem to work :woman_shrugging:

---
tags: 
- type/quote
- "#4family"
aliases:
quote: “Every person you meet knows something you don’t; learn from them.”
author: "[[H. Jackson Brown]]"
reference:
year:
source: "[[the Daily Quote app]]"
source-link: ‎https://apps.apple.com/us/app/daily-quote-positive-quotes/id586028606
featured:
---

## H. Jackson Brown on learning from every person you meet
> [!QUOTE]
> `= this.quote`
> — `= this.author`, `= this.reference`

**Source**
- `= this.source`, `= this.source-link`

Thank you for your reply!

What do you mean by “doesn’t work” and “half of the time”?

  • Some quotes appear prefilled in the resulting code and some quotes don’t pick up the properties. I listed one example of each: the first quote shows up perfectly fine; the second has blanks instead of text. I think you can see it…

How do you apply the template ? What plugin(s) do you use ?

  • I click on “Insert Template” link and select the template I showed here from the list. Nothing else.

you aren’t sharing the results as raw markdown

  • I thought I am! I just copied the raw source code as I was typing this - is there a different way to share it?

I had to improvise and correct some things in the YAML

  • Thank you!! I am still new to this: what am I doing wrong in YAML? Everything needs to be in quotation marks? Tags have to be on a separate line? I can’t make tags coma separated? I tried this quote both with “#4family” and without - still same result :((

One more question: If the quote has multiple paragraphs/lines (E.g. if I wish to insert a poem) - what’s the correct syntax to insert it? And what if quote has quotation marks, colons, etc?

Thank you so much!!

Your forum post is garbled up with various formatting. To properly enclose code within a forum post I suggest surrounding your raw markdown text within four backticks, ````. This will ensure that both the ordinary text and any potential code blocks will display properly, and that single and double quotes are not messed with.

Back to your question, I’m a little baffled whether your quote template has a frontmatter or not. I’m hoping it is just something like the following:

 > [!QUOTE]
>  `= this.quote`
>  — `= this.author`, `= this.reference`

### Source
<!-- Always keep a link to the source- --> 
- `= this.source`, `= this.source-link`

This will when inserted use dataview to pull information from the frontmatter of the note it’s inserted into to present the given quote.

If on the other hand your template also includes the frontmatter, you’ll get into problem if the note you insert the template into already has a frontmatter.

Using the template above with the two frontmatters you provided, they do repeat the quote into the notes. But let me come back to this one at the end…

However, I would strongly suggest that you update your links within the frontmatter to be proper links. That is to write them as "[[My page]]" which will allow them to be recognised as proper links by Obsidian, and be included in backlinks and so on.

Having multiline quotes within the frontmatter could be slightly tricky, but you could try doing <br >. Doing quotes should be as easy as using \".


Getting back to the frontmatter/template thingy, if this is a template you’re using to record new “quote notes”, where the quote is displayed within that note, you should indeed have the frontmatter before the other parts of the template, but you should also be aware of a caching issue with dataview.

The issue is that sometimes if the query doesn’t change, but the text in the note changes, the query doesn’t update properly. In other words, if you insert the quote template and view it in either live preview or reading mode it doesn’t show anything since there is nothing in the quote property.

If you then proceed to update the quote property, it might not display the quote in the section below since dataview has failed to detect the change related to the query: `= this.quote`.

This could, when I think about your wording in the request, be what you describe as the template only working half the time. To circumvent this caching issue, I’ve found three options:

  • Change the query before switching to live preview or reading mode. This could be as simple as adding/removing a space before the last backtick
  • Reopen the quote note. I.e. you could go back to the previous note, and then forward using the arrows in the top left of the note window (for the page history of this tab)
  • Trigger a rebuilding of the view, which could be done by having a button trigger a javascript doing the command: await app.workspace.activeLeaf.rebuildView()

I often resort to adding/removing space if I encounter this issue, but you could try reopening the files not working in your case, and see if that fixes the issue.

I did experience this issue when changing the quote to include some quote characters and the <br > element, so I added a space, and it showed up properly.

3 Likes

OMG thank you so much for all the comments!!!
Retyping the post with code separators - hopefully, it will be more clear and less garbled!!!
Do let me know if I can just edit the original…

I found this very cool piece of code to create templates for recording quotes. Unfortunately, it works half of the time. What am I doing wrong?

TEMPLATE:

---

tags: type/quote
aliases:
quote:
author:
reference:
year:
source:
source-link:
featured:

---

# {{Title}}

> [!QUOTE]
> `= this.quote`
> — `= this.author`, `= this.reference`

### Source

* `= this.source`, `= this.source-link`

## QUOTE FILE WHERE IT WORKS VERY WELL

tags: type/quote
aliases:
quote: “If anyone can prove and show to me that I think and act in error, I will gladly change it—for I seek the truth, by which no one has ever been harmed. The one who is harmed is the one who abides in deceit and ignorance.”
author: [[Marcus Aurelius]]
reference: [[Meditations, 6.21]]
year:
source: [[The Daily Stoic]]
source-link: [[The Daily Stoic#Chapter 117 April 25. There’s Nothing Wrong with Being Wrong]]
featured:

---

# Marcus Aurelius on accepting an error

> [!QUOTE]
> `= this.quote`
> — `= this.author`, `= this.reference`

^bd1e85

### Source

* `= this.source`, `= this.source-link`

QUOTE FILE WHERE IT DOESN’T WORK:

---

tags: type/quote, #4family
aliases:
quote: “Every person you meet knows something you don’t; learn from them.”
author: [[H. Jackson Brown]]
reference:
year:
source: [[the Daily Quote app]]
source-link: [‎Daily Quote - Positive quotes on the App Store](https://itunes.apple.com/app/apple-store/id586028606?pt=529250&at=11lda9&ct=shdailyqotd&mt=8)
featured:

---

# H. Jackson Brown on learning from every person you meet

> [!QUOTE]
> `= this.quote`
> — `= this.author`, `= this.reference`

^12b8c4

### Source

* `= this.source`, `= this.source-link`

Please advise what am I doing wrong?

Thank you so much for your comments!!!
I reposted all the code below…
And when I say it works half of the time - it is not for the same quote. Each quote is either working or it doesn’t get displayed. I don’t understand what you mean by displaying frontmatter twice… I list the quote, the author, the references in YAML and then trying to build the view down below. On certain quotes, it doesn’t show the required text (I have an example of each). As I enter the quote from scratch, if at some point it “stops” showing the text in the lower portion - no matter what I delete or change, it never goes back to show anything in that section (I tried adding fields one by one to see which one breaks it). Really wish to understand better how it works and what’s the propper syntax is. Please see the actual code blocks to correct whatever it is that I need to do differently!!
Thank you so much!!

This was posted on the web somewhere?

Excellent question! Yes, it would be helpful and yes, I originally found it, modified it a bit, can’t find the original again :((

You should get a notes app so you can write things like that down! :stuck_out_tongue_winking_eye: (I’ve been there. :sweat_smile:)

I just wanted to make sure you weren’t (knowingly) asking us to debug ChatGPT output. Carry on!

No, no, no - no chatGPT. It was an article or a video that I can no longer find, that I modified myself - knowingly, unknowingly. I am still super new to Obsidian and would immensely appreciate figuring out what makes the same code work in some situations, and fail in others.

I don’t know Templater and don’t think this should matter to it, but in the non-working example’s tags you have a hashtag (#4family). Tags in properties need to not have the # because that indicates comments in YAML (the language that properties use).

1 Like

Intersting!
I tried it both ways! The code shows up successfully with the same syntax in this case:


---
tags: type/quote, #4family 
aliases: 
quote: To believe in the things you can see and touch is no belief at all - but to believe in the unseen is a triumph and a blessing.
author: [[Abraham Lincoln]]
reference: 
year:
source: 
source-link: 
featured: 

---

# Abraham Lincoln on a power of believing into things you cannot see yet

<!-- Quote and author from frontmatter goes here. Also used for Dataview list of quotes. -->

> [!QUOTE]
>  `= this.quote`
>  — `= this.author`, `= this.reference`
### Source
<!-- Always keep a link to the source- --> 
- `= this.source`, `= this.source-link`

Also if it stops showing the code, no matter what I edit in the text, remove, or even delete - the text quote stays missing. There seems no way to go in the code that stopped showing the quote - chang the text, remove everything - and get it to show anything again.

What ese can I be messsing up in YAML? Besides recreating the notes - is there any way for me to debug it, any suggestions what else I might be doing wrong?

If your query stops showing stuff, or doesn’t show the new version of changes, you could just close that quote note and open it again. Another version is to use the page history, and go back and forth again to the same quote file. A slightly more advanced alternative is to use either Templater or QuickAdd to trigger a command to rebuild the view. Here are two links to threads discussing how to do this using QuickAdd or another one using Templater.

If your properties doesn’t show, or you get a message on invalid frontmatter/yaml, I’ve found that easiest way is simply to move the lower code fence around to see where it doesn’t accept my suggestion for properties. If you start with moving the lower code fence, aka ---, into the middle of your frontmatter, and it displays correctly, then your error is in the lower half. If it doesn’t show, it’s between the fence and the start. In either case, move the fence half way into the offending section, and repeat until you find the line you think is the culprit.

After locating the line, move the fence back to its starting point, move the offending line out of the frontmatter, and see if the rest is OK. And now, you can focus on the line trying to understand why it’s not accepted. Often it is due to a strange symbol not being interpreted as text, like the colon, :, and you solve it by adding straight quotes around the value, " ... ".

1 Like

Thank you so much for your suggestions!!
I noticed that if the quote contains “:” it would break the code, even if it is enclosed in double quotes. E.g. “John says*:* this is right.” - will break it. “John says, this is right” - will work.

Any way to escape it and still insert punctuations like this into the quote when it is in frontmatter?

What breaks where with the colon? If I define the quote using: quote: "something : colon inserted: something", it works fine to do `= this.quote `. So please be a little more specific on how and when it doesn’t work.

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