Skip to content

Run Templater File Button Action Breaks & Is Incorrect #522

@Graywaren

Description

@Graywaren

Please fill out these Check-boxes

  • I checked for existing similar issues
  • I checked that the plugin is up to date
  • The issue persists with all other plugins and themes disabled

Plugin Version

1.3.4

This Issue Occurs on

  • Windows
  • Linux
  • macOS
  • Android
  • iOS

Debug Info

SYSTEM INFO:
	Obsidian version: v1.8.7
	Installer version: v1.8.4
	Operating system: Windows 10 Home 10.0.19045
	Login status: not logged in
	Language: en
	Insider build toggle: off
	Live preview: on
	Base theme: adapt to system
	Community theme: none
	Snippets enabled: 0
	Restricted mode: off
	Plugins installed: 4
	Plugins enabled: 4
		1: Meta Bind v1.3.4
		2: JS Engine v0.3.1
		3: Dataview v0.5.67
		4: Templater v2.10.0

RECOMMENDATIONS:
	Community plugins: for bugs, please first try updating all your plugins to latest. If still not fixed, please try to make the issue happen in the Sandbox Vault or disable community plugins.

Describe the Issue

When using a button to run the "Run Templater File" action, templates break or pull incorrect information. For example, when using this action all references to the current file use the template's file and not the note the button is present in. Sometimes the template just errors as well. This behavior does not occur if you run the exact same template file via a command action instead.

Here's a simple example that prints the file title and logs the current file's tfile in the console:

The templater script, in a file named "Log tFile.md"

<%* 
tR = ''; // this line makes templater ignore the frontmatter of this template file

const tfile = tp.file.find_tfile(tp.file.title);

console.log("Current tfile")
console.log(tfile)

-%>
<% tp.file.title %>

When inserted into a note named "You Remind Me Of The Button.md" via the templater modal or using the hotkey/command for that template or using a meta bind button using the command action the console logs the tfile for "You Remind Me Of The Button.md" and prints the file title at the cursor. All is well.
Image
Image

Here's the button using the command action:

```meta-bind-button
label: Log tFile - command
icon: ""
style: default
class: ""
cssStyle: ""
backgroundImage: ""
tooltip: ""
id: ""
hidden: false
actions:
  - type: command
    command: templater-obsidian:Testing Templater/Log tFile.md
```

However, if you instead run that script by using a button with the "Run Templater File" action, the tfile for "Log tFile.md" is logged into the console instead and absolutely nothing is printed in the note.
Image

Here's the button using run template file action:

```meta-bind-button
label: Log tFile - runtemplaterfile
icon: ""
style: default
class: ""
cssStyle: ""
backgroundImage: ""
tooltip: ""
id: ""
hidden: false
actions:
  - type: runTemplaterFile
    templateFile: Testing Templater/Log tFile.md
```

I've also had templates entirely fail and error. I had this error occur when running a template file in my vault that works perfectly when using the same file as a command action instead of run templater file.
Image

Steps to Reproduce

  1. add Templater to the metabind example vault
  2. set templates folder in templater settings
  3. add the tfile logging script in post to your templates folder
  4. add that template as a template to add a hotkey for in templater settings
  5. create a new note
  6. add a button that triggers the tfile logging script using the command action
  7. add a button that triggers the tfile logging script using the run templater file action
  8. click both buttons

Expected Behavior

I would expect command > insert template file and run templater file to work identically and that the run templater file action would be compatible with all templates that otherwise work when used by inserting via templater or hotkey etc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugUndesired behavior caused by this plugin

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions