Buttons: create new note from text with multiple lines

With the plugin Buttons, I have created a button to create a new note with the given text and open it in a split pane:

```button
name add value
type note(<%"my_folder/" + tp.date.now("X")%>, split) text
action line1\nline2
templater true
color green

It works but does not convert \n to a new line character, so I get just one line in the newly created note with the backslash and n characters verbatim: line1\nline2.

I want to have two lines instead. How to achieve that?

Is there any change if you use action "line 1\n line 2"?

I’m on mobile, so can’t test it myself right now.

You mean put the text in quotes? - I tested it. Unfortunately, the result is still one line, just with the quotes at the beginning and at the end.

It looks like you can use HTML, so I believe action line1<br>line2 should work.

1 Like

I’m positively surprised that you got the template stuff to work within a button, I’ve raised an issue and the plugin developer said (my words) that it didn’t always work, so they suggested using a template instead.

And with regards, to your request to add multiple lines, I think you’ll get better result if you add a template instead of a text. In other words, make yourself a template like, newNoteButton:

<% tp.date.now() %>

First line
Second line

And then use a button like:

```button
name add value
type note(<%"my_folder/" + tp.date.now("X")%>, split) template
action newButtonNote
templater true
color green
```

Then you can add as many lines as you want, keep the button “clean”, and have a stable output. I’m not sure whether the “, split” is the best variant, as it keeps splitting my window in two, but I’m not sure what the alternatives are.

1 Like

The button issue known to me with templater true and type [append|prepend|line] ... text - that is all kind of operations on the note where the button lives in, let’s name it “button’s note” - is:
Clicking the button does execute all the Templater commands in the button’s note, but immediately after that the content of the button’s note as it was before clicking the button is restored again. So, you just see some changes in the note flickering and gone. That’s a kind of feature but only if you want to go your text into another note (i.e. type is note, and not [append|prepend|line]):

The command will be converted to its value when the button is clicked and converted back to the command after.

If you’re operating inside the button’s note, then it’s a feature killer. Besides of that, it does collateral damage on the rest of your note if there are Templater commands in other places - even if the Templater commands are in other buttons.


Thanks for the template suggestion. That’s a valid option. But with a drawback in my use case: the name of the new note to create is dependent on data in the button’s note - (not as in the snippet given by me above; I simplified my use case for the purpose of this forum post). The text I want to go into the new note is dependent on data in the button’s note, as well. That’s why I prefer to keep all my Templater commands affecting the new note in one place; here: in the button code block.

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