obsidian-meta-bind-plugin icon indicating copy to clipboard operation
obsidian-meta-bind-plugin copied to clipboard

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

Open Robomunkie opened this issue 9 months ago • 1 comments

Please fill out these Check-boxes

  • [X] I checked that the plugin is up to date
  • [ ] The issue persist with all other plugins and themes disabled

This Issue Occurs on

  • [X] 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.

Robomunkie avatar May 08 '24 06:05 Robomunkie

I haven't troubleshot this yet, but my first guess would be that this is either a result of how meta bind interacts with templater or an issue in templater.

mProjectsCode avatar May 08 '24 09:05 mProjectsCode