Templater icon indicating copy to clipboard operation
Templater copied to clipboard

Folder templates needs better documentation, both in app and on docs site

Open huachuman opened this issue 1 year ago • 8 comments

Plugin information (please complete the following information):

  • OS: Windows 11
  • Templater version: latest
  • Obsidian version: latest
  • Templater settings: "Templates" folder (default?)

Describe the bug It's not executing code in notes. I put the following inside a template but when creating a new note based on that template, it doesn't rename the note.

<%* let title = "SomeTitle"; await tp.file.rename(${title}); _%>

It also does not execute code anywhere, like

[[<% tp.date.now("YYYY-MM-DD") %>]]

Just renders as <% tp.date.now("YYYY-MM-DD") %>

Expected behavior The code works

Screenshots

Additional context I made sure to enable the execute command on new file creation option.

huachuman avatar Apr 19 '23 19:04 huachuman

How are you creating the note? If you're not creating notes using the Templater command Create new note from template, then the template code will not be executed. The template code is executed when running a Templater command, it does not run automatically.

If you want the template code to be executed when creating files without using a Templater command, you can setup folder templates.

  1. Turn on "Trigger Templater on new file creation".
  2. Turn on "Enable folder templates".
  3. Add a folder template. Any notes created in the provided folder will have the provided template applied to it.

If you want a template to be applied to all new notes, regardless of folder, you can setup a folder template with / as the folder.

Zachatoo avatar Apr 20 '23 03:04 Zachatoo

What is a folder template? is it a folder with templates, is it some kind of folder based on a template? Is it a template that applies to files in the folder? This is a confusing term that has too many possible alternative interpretations to tell the reader what it's supposed to be.

This aspect doesn't seem well explained.

I'd venture a small bet that this is one of the main confusions when it comes to new people trying to use this plugin and not understanding why it doesn't work.

Really not obvious, this plugin. And now I can see why so many people can't figure it out.

The average person would assume you just have to install the plugin and you can start using the code.

Setting the folder up and explaining that aspect should be shot right front and center of the user's face whenever they encounter this plugin.

You make a video showing how this plugin works but it's still not explained. It just kind of vaguely points to possible hints with a mouse wiggle. Not really very informative at all about how this all works.

All that being said I have now got it working as intended.

huachuman avatar Apr 20 '23 10:04 huachuman

I agree, it's not obvious to the average user how to use this plugin. That's why people like me like to help in here and on the Obsidian Discord.

I disagree that folder templates should be a more prominent feature. I'd imagine most people are applying their templates manually using a Templater command. At least that's what I've seen in my activities on the Obsidian Discord.

I didn't make any video, I'm just a random stranger helping out, I am not the maintainer of this plugin.

Feedback is appreciated, hopefully at some point we can make this less confusing for future users within the plugin or documentation.

Zachatoo avatar Apr 20 '23 14:04 Zachatoo

Hey this is probably pretty late but I'm getting a bug where if I

  1. Enable "Trigger templater on new file creatoin"
  2. Enable Folder templates
  3. Then Try to create a new note with a template like {{date}}

I only get {{date}} shown instead of the actual date. i.E templater doesn't execute.

However, when using periodic notes/daily notes my daily note template executes. Also when using "Insert Template" manually, I get the date as expected i.e templator executes. This leads me to believe folder templates don't trigger Templater on new file creation

Any idea why this would be the case?

NishantDate avatar Jan 30 '24 15:01 NishantDate

Because {{date}} is not Templater syntax, it's periodic notes syntax.

You need to use tp.date.now instead.

Zachatoo avatar Jan 30 '24 15:01 Zachatoo

Thank you for the quick response! Is there templator docs for "time" as well?

NishantDate avatar Jan 30 '24 15:01 NishantDate

You'll also use tp.date.now() for times. You'll just pass a different format, for example hh:mm. The docs have a link to the moment docs for all the format tokens you have access to.

Zachatoo avatar Jan 30 '24 15:01 Zachatoo

I was blind. I see them now. Thank you again!

NishantDate avatar Jan 30 '24 15:01 NishantDate