Templater
Templater copied to clipboard
Example for tp.hooks doesn't work
Plugin information (please complete the following information):
- OS: Windows 10
- Templater version: 1.18.0
- Obsidian version: v1.4.16
- Templater settings: Template folder location: "ZZ4 Templates/", Timeout: "5", Command: "Create new note from template".
Describe the bug The exact example from https://silentvoid13.github.io/Templater/internal-functions/internal-modules/hooks-module.html doesn't work, the file is not linted. Nothing is logged in the console.
Expected behavior
The newly created file should get a key YAML from frontmatter and h1 and note YAML from linting.
Screenshots
Config:
Additional context
I've had issues with linting from Templater in the past (unfixed): #948 (see comments)
They run in parallel, which means they're running at the same time and likely hitting a race condition. Those are two separate examples, not meant to be used together like that.
If you want to run them sequentially, you can do it like this.
<%*
tp.hooks.on_all_templates_executed(async () => {
// Update frontmatter after template finishes executing
const file = tp.file.find_tfile(tp.file.path(true));
await app.fileManager.processFrontMatter(file, (frontmatter) => {
frontmatter["key"] = "value";
});
// Run a command from another plugin that modifies the current file, after Templater has updated the file
app.commands.executeCommandById("obsidian-linter:lint-file");
});
-%>
Oops. Sadly, neither work for me (neither separate nor sequentially). Still nothing in the console.
Can you try it in the sandbox vault? Here's the steps I took to verify I didn't have anything weird on my system, worked for me.
- Open the sandbox vault.
- Install the Templater and Linter plugins.
- Create a folder to put your templates in.
- Add the code from my previous message as the note contents for the template.
- In Templater settings, add your templates folder as your template folder location.
- Open a note.
- Run the
Templater: Open Insert Template modalcomand and select your template from step 4.
Does it still not work for you after these steps?
If it does work after these steps, there must be a setting or another plugin that is causing it to not work for you.
It's adding the frontmatter now, but not linting:
After linting manually:
The behavior is identical for Open Insert Template modal and Create new note from template.
I also ran into this issue and got stuck for a lot time. Obsidian version: 1.5.3 Templater version: 2.1.0 OS version: MacOS 13.6.3