mProjectsCode / mProjectsCode/obsidian-meta-bind-plugin

Meta Bind using Templater (insert / replace) and operability with Templater hook (on_all_templates_executed)

Open
#319 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
1k
Forks
86
PR merge metrics
No merged PRs in 30d

Description

Please fill out these Check-boxes
  • I checked that the plugin is up to date
  • The issue persist with all other plugins and themes disabled
This Issue Occurs on
  • Windows
  • Linux
  • macOS
  • Android
  • iOS
Plugin Version

1.1.0

Describe the Issue

I use a "meta-bind-button" to perform a Templater action (eg. templater: true) through "replaceSelf" / "insertIntoNote" with the respective "replacement" or such button property set to a valid Templater script. In this script, I also setup a Templater hook using tp.hooks.on_all_templates_executed(async () => { ... }); in order to perform a final action upon completion of the Templater event being performed (see https://silentvoid13.github.io/Templater/internal-functions/internal-modules/hooks-module.html).

Unfortunately, the code contained within this Templater tp.hooks... block does not get executed automatically upon completion of the Templater event executed by the Meta Bind button I had created. I know that the Templater hook function itself has been setup to run correctly though, as I can trigger this hook event afterwards (and have executed the code I had setup within it) by forcing a "Templater: Replace templates in the active file" (ALT+R, on Windows) operation on the note containing my Meta Bind button and Templater action.

Steps to Reproduce
  1. Setup a Meta Bind button w/ Templater action, eg. "replaceSelf" :
style: primary
label: 'PRESS ME'
action:
   type: replaceSelf
   replacement: '/MYTEMPLATECODE'
   templater: true
  1. Setup a Templater code template (eg. "/MYTEMPLATECODE") :
<%*
   tp.hooks.on_all_templates_executed(async() => {
      console.log("Hello World!");
   });
-%>
Your button has been replaced!
  1. While watching the console, press the button - you will not see "Hello World!", but you will see the text "Your button has been replaced!" on your note, replacing your button.
  2. Now, trigger the Templater action (Templater: Replace templates in the active file) on your note containing your button.
  3. The console will then display "Hello World!", printed from the triggered hook code block configured above.
Expected Behavior

I would have expected that the code block contained within the Templater hook action would have been executed automatically upon completion of the Templater action operation of the Meta Bind button.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with a Meta Bind button using the replaceSelf or insertIntoNote action and templater: true, then trace how the action invokes the Templater template and its on_all_templates_executed hook. Compare the button-triggered operation with Templater: Replace templates in the active file. Done means the hook logs "Hello World!" automatically after the button action completes.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.