Including new lines in arguments to action-sendmessage

I would like to give a mini-template for the text field in <$action-send-message $message="tm-new-tiddler" ...> I would like my new-question button to default the text to this:

''Question'':


<!-- when ready -->
''Answer'':
<!-- remove these comments -->

I tried this:

<$action-sendmessage $message="tm-new-tiddler"
  title="New Question"
  tags="[[Question]]"
  text="''Question:''\n\n\n<!-- when ready -->\n\n''Answer:''\n\n<!-- remove these comments -->"
  answered="no"
  for=""/>
\end

But the backslash characters appear literally in the text. Another added level of backslashes simply appear there as well. Is there a simple way to handle this?

Hi @Scott_Sauyet

Try this:

<$action-sendmessage $message="tm-new-tiddler"
  title="New Question"
  tags="[[Question]]"
  text="""''Question:''


<!-- when ready -->

''Answer:''

<!-- remove these comments -->"""
  answered="no"
  for=""/>

Fred

1 Like

triple quotes as ^^ above """ allow for a surprising amount of coding within them, but the best result I’ve had with tm-new-tiddler text is to just straight transclude a tiddler as the attribute (eg text={{QuestionCommented}}).

It frees up a lot of editing restrictions, and you can dig yourself deeper transclusions in those too.

3 Likes

If you want to avoid using either tripled double-quotes or a separate tiddler, you could also achieve your desired result by using a macro to define the target tiddler text, like this:

\define newQuestionButton()
<$button>New Question
<$action-sendmessage $message="tm-new-tiddler" title="New Question" tags="[[Question]]"
  text=<<newQuestionText>> answered="no" for=""/>
\end

\define newQuestionText()
''Question:''


<!-- when ready -->

''Answer:''

<!-- remove these comments -->
\end

<<newQuestionButton>>

Note that when a macro is used as a widget param value, it is NOT parsed (“wikified”). Thus, in the above code example, the contents of <<newQuestionText>> are used exactly as defined, with all the whitespace and HTML comments intact.

-e

1 Like

Of course. I should have tried that.

Thank you. I should have tried that too.

And I also should have tried that! Thank you.

Okay, three answers, none of which are really new to me, and certainly none obscure. I blame it on it being the end of a long day of work!

Thank you all very much!

You can use an action-createtiddler widget with a template. See the examples

2 Likes

Looking at the stringify operator it will convert line feeds to \n so if we had a destringify convert \n to a newline, we could easily define a function or even add to the output of a filter made into a string with join any of these characters. I have found the charcode operator useful sometimes but you need a look up table.

  • I expect someone with javascript skills could clone the stringify and reverse its function.

…aaaaand we have a winner!

I’d been avoiding ActionCreateTiddlerWidget because of this line from the docs:

There are several differences from the tm-new-tiddler message:

  • The new tiddler is not automatically displayed in the story river

Without fully understanding the implications of the very next line:

  • The title of the new tiddler is made available for subsequent operations

I wanted to use the $basetitle here, so I kept looking back to this, and kept stopping over this issue. But, as described in Example 5, this allows me to create the widget and then immediately open it for editing in the river.

Thank you very much for the pointer!

Yes, from experience in many languages with C-style syntax (including JS) I simply assumed that the string would already be interpreted that way. The backslash is simply how important control characters are embedded in strings. You see it, for instance, in JSON, which escapes any embedded double quote marks with a backslash.