Some old code that didn't work - and a tiny change to make it work

74 views
Skip to first unread message

Joe Armstrong

unread,
Jan 31, 2019, 4:30:29 AM1/31/19
to TiddlyWiki
Hello,

I wanted to make a button that adds a tag to a tiddler when pressed.

I googled a bit and found some code from 2013

This was in a thread entitled
   [TW5] - Is it possible to toggle a tag with a button?

It had this code


<$fieldmangler>
  <$list filter="[is[current]tag[MeTag]]">
    <$button message="tw-remove-tag" param="MeTag">remove MeTag</$button>
  </$list>
  <$list filter="[is[current]!tag[MeTag]]">
    <$button message="tw-add-tag" param="MeTag">add MeTag</$button>
  </$list>
</$fieldmangler>


Not quite what I wanted so I changed to this:

<$fieldmangler>
<$button>
<$action-sendmessage $message="tm-add-tag" param="my tag"/>
   click to add tag 
</$button>
</$fieldmangler>

But this didn't work -- more searching ... and I changed it to this:


<$fieldmangler>
<$button>
<$action-sendmessage $message="tm-add-tag" $param="my tag"/>
   click to add tag works
</$button>
</$fieldmangler>

The *only* difference is 'param' has become '$param'

What about the documentation?


Says the argument should be 'param' so it agrees with the 2013 TW but not the current TW.

So is the documentation correct and the
implementation wrong - or vice versa?

I know this is a terribly small change 'param' vs '$param' but for a beginner like me these discrepancies are very difficult to recognise and pin down.

When stuff doesn't work as advertised I use my beginner strategy
 
     1) search for an example
     2) cut and paste
     3) pray

And it's *very* frustrating to find old code (which did work in 2013) which does not
work today (this is a symptom of a much deeper problem which actually Transclusion and non-mutable
data solves, but I won't bore you with the deatils here) - this is the point where many beginners
give up - they do so silently and don't flood forums with questions - so we never know why
they gve up or when - we just have to guess.

It seems like "$" attribute names are fixed and any other names can be chosen by the user.

I've seen 'param' mentioned all over the place at tiddlywiki.com - should it be '$param' everywhere????

When did the names change and why?

Cheers

/Joe

S. S.

unread,
Jan 31, 2019, 5:28:06 AM1/31/19
to TiddlyWiki

It appears the documentation can be misleading if not read in the correct sequence.

The $param you are setting comes from the attribute in action-sendmessage widget
<$action-sendmessage $message=... $param=... $name=... $value=... OtherNamedParameters=... >

The parameter value that you can use for attribute $param is referred to as param in those many actions available as shown in the Messages tiddler, such as in this case of the tm-add-tag message, the param(eter) to use for the $param attribute is: Name of tag to add

Perhaps you can suggest a way to word the documentation to make this clearer.

Regards

TonyM

unread,
Jan 31, 2019, 6:33:52 AM1/31/19
to TiddlyWiki
Joe,

As per S s answer but if I can explain the use of parameters occur when a widget or message may be used to pass other paramters to a macro or widget. By insisting on say $name= it makes it possible in the same macro or widget to set a parameter name="value" or $param= allows param=

Although I have not checked every case I think you will find parameters with leading $ exist whenever there is a desire to allow additional parameters without forcing reserved paramater names to be the exception.

I can see how this may not help in retrospect but help it explains why. Perhaps my explination could be added to the doco, althought it is already implied in some places.

Tony

Joe Armstrong

unread,
Jan 31, 2019, 11:16:15 AM1/31/19
to TiddlyWiki
That makes sense - thank you.

/Joe
Reply all
Reply to author
Forward
0 new messages