combine <<currentTidderl>> with macro $variable$

64 views
Skip to first unread message

Dave

unread,
Mar 19, 2017, 12:38:21 AM3/19/17
to TiddlyWiki
I would like to have a macro like this

\define notes(side)
<$edit-text tiddler="notesInFields" field="<<currentTiddler>>.$side$" >
\end

that refers to a fieldname that combines the current tiddlers title with a variable provided by the macro where its called


So in this case I could have <<notes left>> in a tiddler named "Foo" and it would keep the text that's written in the text box in a field called "Foo.left"

As its written, however, the actual field name is "<<currentTiddler>>.left".

I tried without quotes, and using variations with the wikify widget, and also using {{brackets}} but am not having  success.


Any suggestions?

thanks,
- Dave


Eric Shulman

unread,
Mar 19, 2017, 1:24:56 AM3/19/17
to TiddlyWiki
Try this:

<$edit-text tiddler="notesInFields" field="$(currentTiddler)$.$side$" >

 
Within a macro definition, all instances of $var$ are replaced with the corresponding values *passed into the macro as parameters*.  Similiarly, all instances of $(var)$ are replaced with corresponding values of *variables that are already defined outside the macro*.

Thus, in the above line, the $(currentTiddler)$ value is replaced with the actual name of the tiddler (e.g., "Foo"), and the $side$ param is replaced by whatever is passed in.  After the text substitutions are done, the full syntax is then "returned" for parsing.  Thus, the syntax
 ... field="$(currentTiddler)$.$side$"
is actually turned into
... field="Foo.left"
before other processing is performed, giving you the results you want.

enjoy,
-e
Eric Shulman
TiddlyTools: "Small Tools for Big Ideas" (tm)
InsideTiddlyWiki: The Missing Manuals

Dave

unread,
Mar 19, 2017, 5:04:30 PM3/19/17
to TiddlyWiki
Thank you Eric :)

I never really think of the built-in macros (that's the proper term, right?) as variables, but they are basically functions, which are glorified variables, hey?

Reply all
Reply to author
Forward
0 new messages