Hooks Module

This module exposes hooks that allow you to execute code when a Templater event occurs.

Documentation

Function documentation is using a specific syntax. More information here.

tp.hooks.on_all_templates_executed(callback_function: () => any)

Hooks into when all actively running templates have finished executing. Most of the time this will be a single template, unless you are using tp.file.include or tp.file.create_new.

Multiple invokations of this method will have their callback functions run in parallel.

Arguments
  • callback_function: Callback function that will be executed when all actively running templates have finished executing.

Examples

// Update frontmatter after template finishes executing
<%*
tp.hooks.on_all_templates_executed(async () => {
  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
<%*
tp.hooks.on_all_templates_executed(() => {
  app.commands.executeCommandById("obsidian-linter:lint-file");
});
-%>