Buttons with Templater and MetaEdit - trying to update frontmatter value but it keeps reverting

Things I have tried

Below is the Buttons code:

name Mark As Done
type append template
action MetaEdit Complete Template

And below is the MetaEdit Complete Template:

<%*
const {update} = this.app.plugins.plugins["metaedit"].api
const {getPropertyValue} = this.app.plugins.plugins["metaedit"].api
const getMaegeAP = await getPropertyValue("maegeAP", "Maege.md")

await update("maegeAP", getMaegeAP + 20, "Maege.md")
await update("complete", true, tp.file.path(true))
-%>

What I’m trying to do

I have a button configured to append a template that has a Templater execution command, intended to update a frontmatter value in the current note using the MetaEdit API.

When I apply the template the normal way via the command palette the template functions as expected. It’s only when I apply the template via Buttons that the frontmatter value seems to change for a split second, then it reverts to the original value.

Looking through the Buttons issues in GH, it seems like this might be a known bug. I just thought it would be worth posting here in case anyone sees something in my code that stands out as an issue, or if anyone knows a workaround.

I got around this by assigning the template to a hotkey via Templater settings. Assigning the template to a hotkey made it its own command, so that I was able to call the command from the Button arguments:

name Mark As Done
type command
action Templater: Insert templates/Complete Task Template.md

For whatever reason, when I did it this way, the frontmatter value I was trying to update would not revert back to the original value.

1 Like

I’m not entirely sure, but I’ve experienced some strangeness using the buttons and Templater plugins in the same file, and I’m guessing it’s some sort of race condition issue. Like, it could be pushing the edit using the metaedit plugin from within the template, but then the button wants to update the file itself, and that causes the revert.

Glad you found a solution, though!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.