Thanks a lot for your help.
The final goal is to attach the template to a button in order to trigger the code.
Thanks for your comment on the logic issue. I was probably tired yesterday night . Behaviour is the same though.
So far, I tried these triggers which all produce the same behaviour:
- Button triggering a template
- Templater: Replace templates in the active file
Your assumption is probably correct as the file is getting change when the code is triggered and then imeediately changed back.
So to summarize, when I trigger the code:
- The value flickers once and then shows its initial state
- The template disapears (expected)
When I click ctrl + z
- the correct value is shown
- the template comes back
This is so weird…
I tried deactivating all plugins except templater. Same result.
Oh I also tried an example available in chhoumann/MetaEdit: MetaEdit for Obsidian. And it works. But it is displaying a table listing tasks and I don’t want a table…
const {update} = this.app.plugins.plugins["metaedit"].api
const {createButton} = app.plugins.plugins["buttons"]
dv.table(["Name", "Status", "Due Date", ""], dv.pages("#projects")
.sort(t => t["due-date"], 'desc')
.where(t => t.status != "Completed")
.map(t => [t.file.link, t.status, t["due"],
createButton({app, el: this.container, args: {name: "Close"}, clickOverride: {click: update, params: ['status', 'closed', t.file.path]}})])
)
This one even works if the table is inside the targeted file…