Template works fine but then after closing and re-opening it throws errors

What I’m trying to do

I created a template that works fine.

BUT when I close the file or shut down Obsidian, when I reopen it says there is a syntax error.

Things I have tried

I had assumed I accidentally hit an errant key and put in some junk. I tried fixing it but nothing worked. So I copied all the code out to a flat text editor, deleted everything in my template, then added the code back in one line at a time. It worked fine again. Same code.

I thought I had everything fixed but then the same thing happened again the next time I closed and reopened the file.

The error that’s flagged is related to some nunjucks code in the frontmatter. I have a suspicion there may be some automatic unicode conversion on open going - on or something along those lines - but I’ll be darned if I can find a setting anywhere for that.

Here are my specifics:
Obsidian 1.6.5

Enabled Plugins:

  • Advanced Tables
  • Advanced URI
  • Auto Link Title
  • Better File Link
  • Book Search
  • BRAT
  • Calendar
  • Callout Manager
  • Citations
  • Commander
  • Dataview
  • Excalibrain
  • Excalidraw
  • Highlightr
  • Hotkey Helper
  • Hotkeys++
  • Hover Editor
  • Iconize
  • Link Favicons
  • List Callouts
  • Meta Bind
  • Natural Language Dates
  • Note Gallery
  • Note Refactor
  • Pandoc Plugin
  • Pane Relief
  • Paste URL into selection
  • Periodic Notes
  • Quick Switcher++
  • QuickAdd
  • Raindrop Highlights
  • Simple Embeds
  • Snippet Downloader
  • Sortable
  • Style Settings
  • Supercharged Links
  • Tag Wrangler
  • Tasks
  • Templater
  • Text Format
  • Update time on edit
  • Wikipedia
  • Zoom
  • Zotero Integration

Error message: “Syntax error. Your frontmatter is invalid”

Source code:

---
in:
  - "[[Papers]]"
related:
  - "[[Domains]]"
title: "{{title}}"
authors:
  - "{{authors}}"
publicationTitle: "{{publicationTitle}}"
journalAbbreviation: "{{journalAbbreviation}}"
year: '{{date | format("YYYY")}}'
volume: "{{volume}}"
issue: "{{issue}}"
pages: "{{pages}}"
paperType: "{{itemType}}"
abstract: "{{abstractNote}}"
doi: "{{DOI}}"
issn: "{{ISSN}}"
url: "{{url}}"
accessDate: '{{accessDate | format("YYYY-MM-DD")}}'
created: '{{exportDate | format("YYYY-MM-DD")}}'
citekey: "{{citekey}}"
tags: {% if tags.length > 0 -%} {%- for t in tags -%} {%- set newTag = t.tag | lower | replace(" ", "-") %} {{newTag}} {%- endfor %} {%- endif %}
aliases:
  - "{{title}}"
  - "{{citekey}}"
---
{% persist "DMW  (Cornell Notes++)" %}
{% if isFirstImport -%}
## {{title}}
### {{authors}}
> [!User] ## **DMW (Cornell Notes++)**
#### Questions/Cues
- 
#### Notes
- 
#### Summary
- 
#### Relate
- 

> [!Shrink]+ ### Abstract
> {{abstractNote}}

> [!Bookmark]+ ### Author-Defined Tags
> {% if tags -%}
> {% for t in tags %}
> - {% set adTag = t.tag | lower | replace(" ", "-") %} ==[[{{adTag}}]]==
> {% endfor %}
> {%- endif %}
{% endif -%}
{% endpersist %}

> [!Album]+ ### Zotero
> #### *Annotations*
> {% for annotation in annotations %}
> {%- if annotation.annotatedText %}
> - "{{annotation.annotatedText}}", [Page {{annotation.page}}]({{annotation.desktopURI}})
> {%- endif %}
> {%- if annotation.imageRelativePath %}
> - ![[{{annotation.imageRelativePath}}]] [Page {{annotation.page}}]({{annotation.desktopURI}})
> {%- if annotation.allTags %}
> {% for tag in annotation.tags %}
>     - {%- set annoTag = "" ~ tag.tag | lower | replace(" ", "-") %} ==[[{{annoTag}}]]==
> {%- endfor %}
> {%- endif %}
> {%- endif %}
> {% if annotation.comment %}
> - {{annotation.comment}}
> {%- if annotation.allTags %}
> {% for tag in annotation.tags %}
>     - {%- set annotTag = "" ~ tag.tag | lower | replace(" ", "-") %} ==[[{{annotTag}}]]==
> {%- endfor %}
> {%- endif %}
> {% endif %}
> {%- endfor %}
> #### *Entry Notes*
> {%- if notes | first -%}
> {% for note in notes %}
> - {{note.note}}
> {%- endfor %}
> {% else %}
> - *none defined*
> {%- endif %}
> #### *Related*
> {%- if relations | first -%}
> {% for relation in relations %}
> - related: {{relation.citekey}}
> {%- endfor -%}
> {% else %}
> - *none defined*
> {%- endif %}
> #### *Links*
> - [Zotero Listing]({{desktopURI}})

> [!Newspaper]+ ### APA Bibliography Entry
> {{bibliography}}

{% for c in creators %}
{% set fullName = c.lastName + ", " + c.firstName %}
<%* 
if (!tp.file.find_tfile("{{fullName}}")) {
    await tp.file.create_new("{{bibliography}}", "{{fullName}}" + ".md", false, "+");
}
%>
{% endfor %}


Obsidian enforces YAML’s rules/specifications (so the Properties/frontmatter/YAML you add to a note are valid) :blush: … and I don’t think we have any control over this.

The template simply have an invalid value (due to the syntax used), noting much more…

Now, if it works as intended, despite the frontmatter syntax error (so, when the plugin you use parses the template and apply it) you still get the expected results, I wouldn’t worry about it too much …

You could, potentially and if needed, edit the template in Source mode instead of Live Preview (it won’t change the fact that there is an “invalid YAML” but at least, it won’t scream at you :sweat_smile: )

I don’t know which plugin uses this syntax though :thinking:, so I don’t know if you could escape the opening and closing --- of the YAML block (so Obsidian won’t try read it and render it as Properties) like it’s feasible with Templater:

<% "---" %>
created: <% tp.date.now( ... ) %>
<% "---" %>

OK, that makes perfect sense. Thanks!

1 Like

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