Properties UI: Support editing template files

Right now, user must edit template files in source mode.
It would be nice if template files were detected and the properties UI/UX could handle them.

Steps to reproduce

  1. Update template settings to use templates directory (e.g. Templates)
  2. Create file Templates/Example template
  3. Add something like the following using a date template variable into Templates/Example template
    ---
    date property: {{date:YYYY-MM-DD}}
    ---
    
  4. Add another property in Live Preview mode (or rename a property)
  5. Try to use template or view in source mode to see your templated property has been mutated and is unusable

See Editing a Template using Properties UI alters it in a destructive way for another report with images that isn’t on the bug forum.

Did you follow the troubleshooting guide? [Y/N]

Expected result

I expect my template file to retain it’s templated variables and still be insertable and usable.

Actual result

The file property in the frontmatter is corrupted and unusable as a template afterwards.

date property:
  "{ date:yyyy-MM-DD }": 

Environment

SYSTEM INFO:
	Obsidian version: v1.7.7
	Installer version: v1.5.3
	Operating system: Darwin Kernel Version 23.6.0: Mon Jul 29 21:13:00 PDT 2024; root:xnu-10063.141.2~1/RELEASE_X86_64 23.6.0
	Login status: not logged in
	Language: en
	Insider build toggle: off
	Live preview: on
	Base theme: adapt to system
	Community theme: none
	Snippets enabled: 1
	Restricted mode: off
	Plugins installed: 5
	Plugins enabled: 5
		1: Tasks v7.14.0
		2: Auto Link Title v1.5.5
		3: Dataview v0.5.67
		4: Tag Wrangler v0.6.1
		5: Smart Connections v2.3.47

RECOMMENDATIONS:
	Custom theme and snippets: for cosmetic issues, please first try updating your theme and disabling your snippets. If still not fixed, please try to make the issue happen in the Sandbox Vault or disable community theme and snippets.
	Community plugins: for bugs, please first try updating all your plugins to latest. If still not fixed, please try to make the issue happen in the Sandbox Vault or disable community plugins.

This also happens in a fresh/sandbox vault.


Additional information

example gif using sandbox fault

this is not a bug. As I replied in the other thread, you need to edit template files in source mode (they are not valid YAML).

I agree that this workflow is not ideal. You can search open a FR to better handle this case.

Sorry, I didn’t realize there was a link to a “bug graveyard” post in the other thread I posted, and thought it should be surfaced in the bug forum rather than the help forum.

I disagree with your categorization of this not being a bug. This doesn’t only happen when mutating properties via live preview. It also happens if you rename a file property. It defies user expectations when modifying a template file using the core bundled Templates plugin. This limitation isn’t mentioned in either the templates documentation or the properties documentation. There is no validation on save of a file that has invalid YAML in the frontmatter in source mode. These, to me, all qualify this as not-working-as-intended.

Whether it qualifies as a bug or feature request (I think it quite clearly fits the criteria of what I would consider a bug), I think it does not behave as any user would expect. I think to address this usage of templates, I will have to do is use the Templater plugin. I believe their template substitutions are valid YAML strings that will get substituted correctly. But, I would like to see this fixed directly in Obsidian core to obliviate the need for 3P a plugin for this use case.

Regardless, thanks for the quick response.

I created a thread in FR to track this.

I’ve seen a similar issue when using the Templater plugin, when you don’t want it to treat stuff as properties. One workaround we use in that case is to replace the first triplet of dashes with <% "---" %>.

Update: After some more testing I discovered that you could use the following as the absolute first line in your templates: {{date:---}} which effectively disables this as a property/frontmatter section. But when handled by the template engine, it’ll insert the correct start sequence for the section.

This workaround will then allow you to edit your core templates in both live preview and source mode! :smiley:

PS! You might also want to use it for the ending triple-dash, so that the last actual property isn’t considered a heading at level 1… :stuck_out_tongue:

1 Like