Here is a bit of real code of mine:
\define createItemButtons(nature id origin)
<$button actions=<<show$nature$ id:"$id$" origin:"$origin$">> class="show">See</$button>
<$button actions=<<edit$nature$ id:"$id$" origin:"$origin$" clear:"clear">> class="ed">Edit</$button>
\end
This is all very well if the origin variable can be supplied. But this is not always possible. So I had design a variable to take care of that. But I can’t use it because TW syntax doesn’t allow it. I can’t use $(var)$
for a variable set at the same level (but I can for a “let” variable at the same level - go figure!). Thus, I would need an auxiliary function, just to be able to use either $origin$
or $(origin)$
. This is annoying. And even more annoying because that pesty function would be global if my tiddler is tagged with “$:/tags/Macro”, forcing me to create a new tiddler and import it (cumbersome). So the best code I am able to use is illustrated below (using a function as a variable to avoid having the problem of a real function):
\define createItemButtons(nature id origin)
<$let seeBtn="""<$button actions=<<show$nature$ id:"$id$" origin:"$(origin)$">> class="show">See</$button>"""
editBtn="""<$button actions=<<edit$nature$ id:"$id$" origin:"$(origin)$" clear:"clear">> class="ed">Edit</$button>""">
<$set name=origin select=0 filter="[[$origin$] [<currentTiddler>get[host]] [<currentTiddler>] +[dump[3 origins]!is[null]first[]dump[origin selected]]">
<<seeBtn>>
<<editBtn>>
</$set></$let>
\end
How would you rate this code? What would you do yourself?