Thanks for spotting that, I misread the detail.

On Wednesday, July 18, 2018 at 12:53:40 PM UTC+10, Mohammad wrote:
>
> Tony, I think you should change var1 and var2 in your set widget based on 
> talha question
>
> \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>>
>
>
>
> On Wednesday, July 18, 2018 at 5:12:46 AM UTC+4:30, TonyM wrote:
>>
>> An answer more specific to you case
>>
>> \define mymacro(var1 var2)
>> <$set name=result value="$var1$" emptyValue="$var2$">
>> <<result>>
>> </$set>
>> \end
>>
>> But the above does not address if var2 is empty
>>
>> Regards
>> Tony
>>
>> On Wednesday, July 18, 2018 at 10:36:52 AM UTC+10, TonyM wrote:
>>>
>>> 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/6dbd173f-45aa-4be3-ab77-2002ac15b75c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to