Quotes in Scripts: Single, Double, or Triple Double Quotes

  • How do you use quotes in your scripts?
  • When do you use triple double quotes?
  • What is the good practice?

Macros

For macros see: Macro Calls in WikiText

  • I may recommend to ignore quotes when it is possible (e.g <<mymac par1>> instead of <<mymac "par1">>)
  • decide to use single/double consistently ( I use " for strings and ' when a string with " is passed)

Widget parameters

  • when pass another widget as a parameter, use single quote. See below example

A fun example

Write a toggle button in three lines to switch the text of My Tiddler between two values: show/hide and properly show the button caption based on those values.

<$button actions='<$action-listops $tiddler="My Tiddler" $field=text $subfilter="+[toggle[show],[hide]]"/>'>
<$list filter="[{My Tiddler}match[show]then[Hide]else[Show]]"><<currentTiddler>></$list>
</$button>

See how single ' is used instead of """ in above example

1 Like

This is interesting. Personally, I use triple double quotes for the outer level, then single double quotes for the inner level.

<$wikify name="variable" text="""
<$transclude mode="block"/>
""">

I always add a linebreak before starting the text inside the triple double quotes, unless it will affect the rendering.

It feels more natural to me that the outer level has more quotes than the inner level. Probably because I use American English.

If the string gets more complicated (three levels) I move it to a variable instead.

\define myActions()
<$action-setfield text="""
<$transclude tiddler="ThisTiddler" />

---

<$view field="title"/>
"""
tags="notes"
/>
\end

<$button actions=<<myActions>> >click me </$button>

I think best practice is, as you said, consistency :D.

I think this should be a discussion first and the there may be a summary “write up” here in Tips & Tricks as a wiki once there is a consense.

The OP starts with 3 questions, and in the text contains “I may recommend”, which for me indicates, that you are not sure.

So I’d like to move this thread to the discussion category first and remove the wiki-flag

@Mohammad would this be OK for you?

The reason for my suggestion is that I disagree with the first suggestion to remove the quotes from a single word parameter.

I may recommend to ignore quotes when it is possible (e.g <<mymac par1>> instead of <<mymac "par1">>)

There is a reason, why the TW core consistently uses quotes even for single word params, because they are much more robust for new users, if they make changes and insert spaces to the params.

So it highly depends, if you use the wiki yourself only or if you prepare wikis for others. There’s a difference in the best practice “rule set”

2 Likes

I agree that this should be a discussion, and also with always using quotes.

@Mario I removed the Wiki tag and also put this under Discussion!

I’ll throw in my two cents.

I prefer this text='<$action value="this"/>' to this text="""<$action value="this"/>"""
because quotes bloat terribly in the written file. Each one becomes \\\" while single quotes remain '.

That means """this""" contains 22 more bytes than necessary, so I reserve triple quotes strictly for encapsulating $placeholders$.

1 Like

Yea, this may be true for the core, but for normal users I personally like 3 double quotes “”" more like the single quote ’ … From my point of view they are much more visible and indicate, that something special is going on. …

From the “number of bytes” point of view, you are right. We have about 1500 occurrences of “triple double quotes” in the TW repo / tiddlers. So we may be able to save close to 30kByte … Which would be a minified 3rd party library :wink:

An interesting thought. …