Closed ZobaJakColbert closed 5 months ago
I had this issue too so I dived into the source code. The reason this happens is when you have templater true
, it runs templater-obsidian:replace-in-file-templater
on the entire file. This executes all of your templater commands. I found no way to make it work and ended up refactoring how I was creating templates and notes.
Happening to me too
I recently discovered another work around for this issue. You can programmatically create Buttons in Dataview blocks. By doing this, you bypass using Templater markup, and instead write Javascript. When you generate a note from a template, button code isn't execute so you don't have this issue happen.
Example. Instead of this:
```button
name Dodaj akumulator AA
type note(Akumulatory/AA/<% tp.user.getThisAcumulatorNum(tp, "Button 1") %>, split) template
action Szablon - Akumulator
templater true
```button
name Dodaj akumulator AA
type note(Akumulatory/AA/<% tp.user.getThisAcumulatorNum(tp, "Button 2") %>, split) template
action Szablon - Akumulator
templater true
```
do this:
```dataviewjs
const {createButton} = app.plugins.plugins["buttons"];
const { user, file } = app.plugins.plugins["templater-obsidian"].templater.current_functions_object;
const createNote = (buttonString) => {
const number = user.getThisAcumulatorNum(tp, buttonString);
file.create_new("Szablon - Akumulator", `Akumulatory/AA/${number}`, true);
};
const buttonName1 = 'Button 1';
this.container.appendChild(createButton({
app,
el: this.container,
args: { name: buttonName1 },
clickOverride: { click: createNote, params: [buttonName1] }
}));
const buttonName2 = 'Button 2';
this.container.appendChild(createButton({
app,
el: this.container,
args: { name: buttonName2 },
clickOverride: { click: createNote, params: [buttonName2] }
}));
```
Unfortunately this doesn't work on Obsidian Mobile.
I noticed a similar issue with the following button definitions: https://gist.github.com/CaptSolo/b1dec50dd3f8b48925ab80ba3c74009a
When the 1st of the two buttons is pressed, for some reason the command / template for the second button gets executed. That is, the command / template of the 1st button does not get executed at all.
Thanks to @blbaker for a workaround – if the line "templater true
" is removed from button definitions, the problem disappears.
this should be fixed now, reopen if still a problem
Buttons v0.4.19 Obsidian v1.1.16
I put two buttons in one note. Both fire the templater user script, but with different strings. When I run either of them I see in the console that they both run.
First button
^button-NowyAkumulatorPaluszek
^button-NowyAAAAkumulator