Say I have a macro
\define example(v1, v2:"")
\end
If v2 is empty than I want to assign value of v1 to v2. What’s the TW syntax for this?
My apologies for lack of clarification.
I have this macro
\define colors(color:"black", txtcolor:"", bgcolor:"")
<span style="font-size:1em;color:$color$;">■
<span style="color:$txtcolor$;background-color:$bgcolor$;border-radius:5px; margin:1em;padding:9px 12px 10px">
$color$</span>
</span>
\end
What I want to do is, if bgcolor is undefined then use whatever value is assigned to color variable.
I searched the forum. Unfortunately I didn’t quite understand the answers there.
One more thing, instead of using $txtcolor$, I have tried <<txtcolor>> and <<__txtcolor__>> but they didn’t work. Am I correct to assume, inside HTML tags, <<>> syntax does not work?
\define colors2(color txtcolor bgcolor)
<span style="font-size:1em;color:$color$;">■
<span style="color:<<__txtcolor__>>;background-color:$bgcolor$;border-radius:5px; margin:1em;padding:9px 12px 10px">
$color$</span>
</span>
\end
\define colors(color:"black", txtcolor:"", bgcolor:"XXX")
<$vars color=<<__color__>> bgcolorinit=<<__bgcolor__>>>
<$list filter="[<color>] [<bgcolorinit>] +[!prefix[XXX]last[1]]" variable="bgcolor">
<$macrocall $name="colors2" color=<<__color__>> txtcolor=<<__txtcolor__>> bgcolor=<<bgcolor>>/>
</$list>
</$vars>
\end
<<colors "blue" "blue" "yellow" >>\define mymacro(fieldname)
<$set name=fieldname value="$fieldname$" emptyValue="default value">
<<fieldname>>
</$set>
\end
<<mymacro>>
<<mymacro description>><$macrocall $name="othermacroorwidget" inputvalue=<<fieldname>>/>
or outside the macro in wikitext
<$macrocall $name="mymacro" fieldname="description"/>
<$macrocall $name="mymacro" fieldname=<<othermacro>>/>
<$macrocall $name="mymacro" fieldname={{!!description}}/>
Note: field transclusion example Not tested today
The above is not using the <<__fieldname__>> method I am yet to digest. It may reduce the need for $macrocall however this is a nice method to use especially in macros
Macros that you design for re-use, they spell it out and don't rely on the position of values you pass to the macro you are calling.
Additional advanced note:If you use recursion where mymacro calls itself mymacro such as in toc macros, it is a fact that the fieldname $fieldname$ and variable <<fieldname>> will be reused for each invocation thus they have the same name but will not have the same value. So if the recursion went 5 levels deep each invocation will use an independent set of variables called fieldname for each level
Regards
Tony
\define mymacro(var1 var2)
<$set name=result value="$var1$" emptyValue="$var2$">
<<result>>
</$set>
\end\define mymacro(var1 var2:"")<$set name=result value="$var2$" emptyValue="$var1$"><li>v1: $var1$</li><li>v2: $var2$</li><li>v2(result): <<result>></li></$set>\end
<<mymacro test next>><<mymacro test>>