Macros are just “text expanders”. They don’t parse their parameters. Thus, {{!!fieldname}}
is just passed into the macro “as-is” and the parameter reference within the macro definition (i.e., $param$
) is replaced with {{!!fieldname}}
. Then, the resulting macro content is used to replace the original macro call. It is up to the context where the macro was called to determine if that content is “wikified” to produce the final rendered result.
For example, suppose you create a macro like this:
\define showtext(param) <$text text=$param$/>
and then call it like this:
<<showtext {{!!fieldname}}>>
the result is that the original macro call is replaced by
<$text text={{!!fieldname}}/>
which is parsed to display the actual value stored in the fieldname. However, in your example:
\define textfilter(text, filter) <$text text={{{ [[$text$]$filter$] }}} />
the parameter you passed in is inserted into filter syntax. Thus, passing in `{{!!fieldname}} produces the output:
<$text text={{{ [[{{!!fieldname}}]$filter$] }}} />
Take note that the parameter value contained inside the filter syntax is enclosed within [...]
which causes it to be treated as a literal text string and prevents it from being parsed to get the actual value stored in the specified fieldname.
To achieve something like what you expected, you would need to write:
\define textfilter(text, filter) <$text text={{{ [$text$$filter$] }}} />
and then invoke it with:
<<textfilter "{!!fieldname}">>
which would produce the following macro output:
<$text text={{{ [{!!fieldname}] }}}/>
which, when parsed and rendered WILL display the value stored in the specified fieldname.
For your particular use case, it is probably more obvious if you define a macro like this:
\define showrelativedate(field)
<$text text={{{ [{!!$field$}format:relativedate[]trim[ ago]] }}}/>
\end
which you could then invoke via:
<<showrelativedate date-field>>
Also, take note that, when you use the $macrocall
WIDGET to invoke the macro, as in your example:
<$macrocall $name="MacroName" var1={{!!FieldName}} />
the var1
widget parameter IS being parsed before being passed in. Thus, the macro expansion uses the text value contained within the specified fieldname, producing the rendered output you expected.
While this may all seem a bit convoluted and somewhat different from most other languages, TiddlyWiki filter syntax is actually very consistent, even if this is not readily apparent.
I realize that it may seem easier to retreat to your comfort zone by defining macros using Javascript code, but I encourage you to keep trying to use TiddlyWiki native syntax as much as possible. It will probably take some time, but once it “clicks”, it will become surprisingly easy to create filters that achieve some very sophisticated results.
When you get stuck, just ask questions here… we are a friendly group, and are always eager to help people find the solutions they need to make their use of TiddlyWiki successful.
-e