Buttons update 0.3.0

Hey there! :sparkles:Buttons :sparkles:Has been updated with some cool new features.

If you haven’t heard of it before, :sparkles:Buttons :sparkles: Is a plugin that lets you put buttons in your notes to do a variety of things:

  • run commands
  • open links
  • insert templates
  • do some maths

Here’s what’s new:

(special guest appearance of a bug I’ll fix asap)

  • You can add a block-id below a button block. The button block-id can be used to inherit arguments from a button or to remove multiple buttons
  • remove can now be an array of button block-ids to remove (it can still be true to remove the clicked button)
  • replace now takes an array like [startLine,endLine] to define the start and end line to be replaced.
  • append, prepend, remove, replace have been updated to use the button position. name is no longer required.

Can I add a button to add text directly above the button? I keep a running log in my daily notes. Currently use a template but a button at the bottom of the log would be even easier.

Log template

#### 07:34 AM -


name Add Log
type prepend template
action Log Template

One tricky bit is that buttons show in preview but you want to be in edit to write in the log. You can use Templater to switch into edit mode and put the cursor at the log entry point.

Add this to you Log Template if you want that

app.workspace.activeLeaf.setViewState({type: “markdown”, state: {file: app.workspace.activeLeaf.getViewState().state.file, mode: “source”}})

And then put <% tp.file.cursor %> at the point you want to start writing.

Thanks for writing this up.

The button works great, but you make a good point about usability while in edit/preview mode. I’m rarely in preview mode, so this may be more of a learning exercise than anything.

I tried adding your code but only get an error. Template parsing error, aborting. Eta Error: Bad template syntax

1 Like

Didn’t work for me either.

7 months later… 🤦

And another 28 days later someone comes with an actual solution…
@dylan_k and @dddave I had the same error which was for me because of copy pasting the code mentioned here which includes quotes that are not parsable by JavaScript. Also I got a “undefined” printed out after that fix. So for this to work correctly you would need to do something like this:

<% app.workspace.activeLeaf.setViewState({type: "markdown", state: { file: app.workspace.activeLeaf.getViewState().state.file, mode: "source"}}) ? "" : "" %>

This worked for me (also wanting to add new log entries :smiley:


those damn curly quotes will get ya every time.