Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example for tp.hooks doesn't work #1243

Open
Martin-Milbradt opened this issue Nov 13, 2023 · 5 comments
Open

Example for tp.hooks doesn't work #1243

Martin-Milbradt opened this issue Nov 13, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@Martin-Milbradt
Copy link

Martin-Milbradt commented Nov 13, 2023

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
image
image

Config:
image
image

Additional context

I've had issues with linting from Templater in the past (unfixed): #948 (see comments)

@Martin-Milbradt Martin-Milbradt added the bug Something isn't working label Nov 13, 2023
@Zachatoo
Copy link
Collaborator

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");
});
-%>

@Martin-Milbradt
Copy link
Author

Oops. Sadly, neither work for me (neither separate nor sequentially).
Still nothing in the console.

@Zachatoo
Copy link
Collaborator

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.

  1. Open the sandbox vault.
  2. Install the Templater and Linter plugins.
  3. Create a folder to put your templates in.
  4. Add the code from my previous message as the note contents for the template.
  5. In Templater settings, add your templates folder as your template folder location.
  6. Open a note.
  7. Run the Templater: Open Insert Template modal comand 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.

@Martin-Milbradt
Copy link
Author

Martin-Milbradt commented Nov 14, 2023

It's adding the frontmatter now, but not linting:
image
After linting manually:
image

The behavior is identical for Open Insert Template modal and Create new note from template.

@bfcs
Copy link

bfcs commented Jan 13, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants