Talha,
The default value set in the define macro can distract you from another way
of setting a default value, using the setWidgets emptyValue or listwidgets
emptyMessage
In the below example should be sufficient to explain what I mean. Note the
convenience of having an input fieldname value $fieldname$ and variable
<<fieldname>>
\define mymacro(fieldname)
<$set name=fieldname value="$fieldname$" emptyValue="default value">
<<fieldname>>
</$set>
\end
<<mymacro>>
<<mymacro description>>
Then if the macro is calling other macros or widgets use the $macrocall
widget then you can pass <<fieldname>> into those macros
Eg; In the above macro
<$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
On Wednesday, July 18, 2018 at 3:05:46 AM UTC+10, talha131 wrote:
>
> 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?
>
>
--
You received this message because you are subscribed to the Google Groups
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit
https://groups.google.com/d/msgid/tiddlywiki/7340e33e-4939-400e-bebc-9a025603df37%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.