Hi

For anyone who has followed this thread - or just found it and wants to see 
how the solution ended up looking like - here's a glimpse at the code:

\define if(value:"_false_",test,true,else,error) 
<$vars value="""$value$""" test="""$test$"""> 
<$set name="result" filter="[<value>!prefix[_false_]]" value="compare" 
emptyValue="if-error">
<$macrocall $name=<<result>> value=<<value>> test=<<test>> true="""$true$""" 
else="""$else$""" error="""$error$""" />
</$set> 
</$vars>
\end

\define compare(value,test,true,else,error) 
<$vars value="""$value$""" test="""$test$""" true="""$true$""" 
else="""$else$"""> 
<$set name="result" filter="[<value>prefix<test>]" value=<<true>> 
emptyValue=<<else>>>
<<result>>
</$set> 
</$vars>
\end

\define if-error(value,test,true,else,error:"undefined")
//$error$//
\end

\define male() <$macrocall $name="if" value={{!!gender}} test="he" true="male" 
else="female" error="choose gender"/>
\define g() <$macrocall $name="if" value={{!!gender}} test="he" true="he" 
else="she"/>
\define G() <$macrocall $name="if" value={{!!gender}} test="he" true="He" 
else="She"/>
\define g2() <$macrocall $name="if" value={{!!gender}} test="he" true="him" 
else="her"/>
\define G2() <$macrocall $name="if" value={{!!gender}} test="he" true="Him" 
else="Her"/>
\define g'() <$macrocall $name="if" value={{!!gender}} test="he" true="his" 
else="her"/>
\define G'() <$macrocall $name="if" value={{!!gender}} test="he" true="His" 
else="Her" error="gender not defined"/>

<$checkbox field="gender" checked="he" unchecked="she"> <<male>></$checkbox>

<$checkbox field="gender" checked=""> undefined </$checkbox>

!! Gender Test Results

g is ''<<g>>''

G is ''<<G>>''

g2 is ''<<g2>>''

G2 is ''<<G2>>''

g' is ''<<g'>>''

G' is ''<<G'>>''


I now have it working in my "teacher's tool for writing student statements" 
here: måns.dk/udtalelser/test <http://xn--mns-ula.dk/udtalelser/test/>

It's all in Danish I'm afraid. 
The example code is here: http://xn--mns-ula.dk/udtalelser/test/#Helmigers

My danish variant is here: 
http://xn--mns-ula.dk/udtalelser/test/#PronominVariabel

Happy hacking :-)

Cheers Måns Mårtensson

Den lørdag den 8. april 2017 kl. 13.15.24 UTC+2 skrev Måns:
>
> Hi TwWizards
>
> I am attempting to create a couple of global macros which will allow 
> simple text templating.
>
> My question is: How can a create a few simple macros which will render 
> different results depending on a fieldvalue in a tiddler?:
>
> Tagged: $:/tags/Macro
>
> \define name() {{!!surname}}
>
> \define hs() If the value of the field gender is true then show: "he". 
> If gender is false then show: "she". If gender value is empty show: it
> \end
> \define Hs()  If the value of the field gender is true then show: "He". 
> If gender is false then show: "She". If gender value is empty show: It
> \end
> \define hs'()  If the value of the field gender is true then show: "his". 
> If gender is false then show: "her". If gender value is empty show: it's
> \end
> \define Hs'()  If the value of the field gender is true then show: "His". 
> If gender is false then show: "Her". If gender value is empty show: It's
> \end
> \define gender()  If the value of the field gender is true then show: "boy". 
> If gender is false then show: "girl". If gender value is empty show: boy/girl
> \end
>
> <<name>>
>
> <$checkbox field="gender" checked="true" 
> unchecked="false"><<gender>></$checkbox>
>
> <<hs>>
> <<Hs>>
> <<hs'>>
> <<Hs'>>
>
>
> (As usual) I need some kind of "if-logic" ...
>
> Cheers Måns Mårtensson
>
>

-- 
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 tiddlywiki+unsubscr...@googlegroups.com.
To post to this group, send email to tiddlywiki@googlegroups.com.
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/ad4b09be-f791-4dd7-8b03-ca39ce832911%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to