syntax -- are "$"s important?

140 views
Skip to first unread message

@TiddlyTweeter

unread,
Feb 20, 2019, 11:36:25 AM2/20/19
to TiddlyWiki
I'm just starting to (vaguely) understand TW code...
A problem is variations I see in used syntax ... especially about when you use $ or not. I get confused.

Is it ... ?

<$link to="hobbit" ...

or is it ... ?

<$link $to="hobbit"...

Is it ... ?

<$action-sendmessage $message="tm-close-tiddler" $param={{{[has[draft.of]field:draft.of<item>]}}}/>

or is it ... 

<$action-sendmessage $message="tm-close-tiddler" param={{{[has[draft.of]field:draft.of<item>]}}}/>

(Thanks to Thomas for that one: https://groups.google.com/d/msg/tiddlywiki/tUwDeDPQyDc/ie4Zyhx8BQAJ)

Just trying to get clearer
Josiah

@TiddlyTweeter

unread,
Feb 20, 2019, 11:37:15 AM2/20/19
to TiddlyWiki
repeat for email ...

Joshua Fontany

unread,
Feb 20, 2019, 3:56:12 PM2/20/19
to TiddlyWiki
From my understanding of the docs and poking around while building my Json plugin, I would say that yes, they are important.

I still find myself looking up almost every widget to see if I am using the right syntax.

The trend that I have seen is that parameters that start with $ are "named parameters", those that do not are collected into a 'paramObject' internally, and are "optional parameters". I'm not sure if this can be generalized exactly like that..... but is how I think about them. This can be seen clearest in the <$action-setfield> widget. If you don't have $tiddler & $field it won't work ($value is optional). If you have $tiddler, but no $field or $value (etc), but you do have a set of optional parameters, such as  <$action-setfield $tiddler=<<currentTiddler>> name="the Name" date="the Date" location="the Location"> then those are interpreted as !!field = "value".
AttributeDescription
$tiddlerThe title of the tiddler whose fields are to be modified (if not provided defaults to the current tiddler)
$fieldOptional name of a field to be assigned the $value attribute
$indexOptional index of a property in a data tiddler to be assigned the $value attribute
$valueThe value to be assigned to the field or index identified by the $field or $index attribute. If neither is specified then the value is assigned to the text field. If no value is specified, $field or $index will be deleted.
$timestampSpecifies whether the timestamp(s) of the target tiddler will be updated (modified and modifier, plus created and creator for newly created tiddlers). Can be "yes" (the default) or "no"
{any attributes not starting with $}Each attribute name specifies a field to be modified with the attribute value providing the value to assign to the field

TonyM

unread,
Feb 20, 2019, 4:23:54 PM2/20/19
to TiddlyWiki
Using $ as a prefix to a parameter name in widgets is only when there is a posibility when you may want to pass a name value the same as the parameter.

$value=v1 allows value=v2 to be used in the same widget. Effectively not blocking you from passing a "value" called value

This you find it in widgets that should permit any parameter=value pair like creating tiddlers, and almost no where else.

Tony

Joshua Fontany

unread,
Feb 20, 2019, 4:25:40 PM2/20/19
to TiddlyWiki
Mahalo (thanks)!!!!

Mohammad

unread,
Feb 21, 2019, 9:50:53 AM2/21/19
to TiddlyWiki
Unfortunately it is confusing

<$wikify name= ...
<$macrocall $name= ...


I would recommend for widget, use widget parameter with $ and everything else without it!
But seems for backward compatibility there are very hard to revise!

--Mohammad

@TiddlyTweeter

unread,
Feb 21, 2019, 10:28:17 AM2/21/19
to TiddlyWiki
Ciao Mohammad

That is a useful reply, because I can use it as a Rule I can understand simply. 

What confused me was seeing uses both with and without "$" that (mainly) worked. 

The problem comes in debugging code where you not sure if you made a logic problem or a syntax error.

Best wishes
Josiah

TonyM

unread,
Feb 21, 2019, 4:32:23 PM2/21/19
to TiddlyWiki
Mohammad,

I may be confusing to you now but with respect it is not.

In wikify you will never need to provide another parameter other than defined in the the wikify macro
AttributeDescription
nameThe name of the variable to assign
textThe text to parse and render
typeThe ContentType of the text (defaults to text/vnd.tiddlywiki)
modeThe parse mode: block (the default) or inline
outputKeyword indicating the desired output type, defaulting to text (see below)

However in The $macrocall widget you may very well want to define a field called "name" and give it a value bvecaue you may have a field called name, thus $name is used for the parameter

The advantage of the widget form is that it allows macro parameters to be specified as widget attributes
parametersMacro parameters specified as attributes
This includes
$macrocall
ActionCreateTiddlerWidget
ActionDeleteFieldWidget
ActionSendMessageWidget
ActionSetFieldWidget
VarsWidget

Each of the above need to be able to have the the parameter name=value thus provide $name=parmval to stop a clash. They are all quite general in nature.

It is actually very simple, Ask yourself in any given widget may you need to be able to set a value (Typically a field) of the same name as on of the documented parameters?

Regards
Tony

Mohammad

unread,
Feb 21, 2019, 4:43:52 PM2/21/19
to tiddl...@googlegroups.com
Hello Tony!
Thank you for clarification. I understood the reason!
But for simplicity I asked why not use $ also for wikify widget attributes! I mean this way it much more simpler to learn.
and it is kind of semantic naming rule.

By the way I respect developer opinion!

I share my own experience, I have to keep tiddlywiki.com open all the time, because when coding (specially a little complex one) I mixed these things and
I had cases, it took me hours to debug the code.

Cheers
Mohammad

TonyM

unread,
Feb 21, 2019, 5:01:59 PM2/21/19
to TiddlyWiki
Mohammad,

I understand but if you used $name in Wikify my rule above would be broken, and it would be impossible to tell when to use it and when not to. The only way out would be to change all widget parameters to begin with a $

This issue can only be solved by understanding why the $ is used and in which cases, which is after all a small list and noted in the documentation.

Regards
Tony

S. S.

unread,
Feb 21, 2019, 8:54:52 PM2/21/19
to TiddlyWiki

Just as a note, the $vars widget is the opposite - the attribute specifying the variable name cannot start with a $

All 7 Action Widgets use $named attributes, so:

$macrocall
$ActionCreateTiddlerWidget
$ActionDeleteFieldWidget
$ActionDeleteTiddlerWidget
$ActionListopsWidget
$ActionNavigateWidget
$ActionSendMessageWidget
ActionSetFieldWidget

I could not easily spot any other Widgets that use them.

Regards

On Friday, February 22, 2019 at 4:32:23 AM UTC+7, TonyM wrote:
Mohammad,

Mohammad

unread,
Feb 22, 2019, 1:27:56 AM2/22/19
to TiddlyWiki
That's quite correct S.S.

I would be great if in your TW Documentation project these difference highlighted.

Cheers
Mohammad

Mohammad

unread,
Feb 22, 2019, 1:28:43 AM2/22/19
to TiddlyWiki
Tony!
 I think the problem is backward compatibility.

Cheers
Mohammad
Reply all
Reply to author
Forward
0 new messages