Macros to show different results all depending on a single field value?

121 views
Skip to first unread message

Måns

unread,
Jun 10, 2016, 3:50:25 PM6/10/16
to TiddlyWiki
Hi TwWizards

I have a radio button which sets a value of a field "gender" to either "male" or "female".

Now I want to create 4 or 5 macros which will show/wikify the value as different results.

I guess some kind of "if evaluation" is needed?
 
Macro 1 should show male as "he" and female as "she" I think it should look like this <<he>> or <<she>>
Macro 1b should show male as "He" and female as "She" <<He>> <<She>>

Macro 2 should show male as "him" and female as "her"  <<him>> <<her>> 
Macro 2b should show male as "Him" and female as "Her" <<Him>> <<Her>>

I guess creating  macros like this is a better and more simple way to achieve what I described in this post.

Cheers Måns Mårtensson 

Mat

unread,
Jun 10, 2016, 6:39:58 PM6/10/16
to TiddlyWiki
Just the other day I was fiddling with some stuff based on the "if-sidebar" macro found in $:/core/macros/CSS

I think the ideas used in that would work for your case.

<:-)

c pa

unread,
Jun 10, 2016, 8:09:50 PM6/10/16
to TiddlyWiki
\define Get_He_She(gender)
     {{He_She##$gender$$}}
\end

\define Get_Him_Her(gender)
      {{Him_Her##$gender$$}}
\end

Create tiddlers

title: "He_She"
text: "
# This tiddler is a Data Dictionary that translates gender designations to personal pronouns

male: He
female: She

"
type: Data Dictionary (application/x-tiddler-dictionary)

title: "Him_Her"
text: "
# This tiddler is a Data Dictionary that translates gender designations to personal pronouns

male: Him
female: Her

"
type: Data Dictionary (application/x-tiddler-dictionary)

Måns

unread,
Jun 11, 2016, 1:28:06 PM6/11/16
to TiddlyWiki
Hi cp a

Thanks a lot :-)

Cheers Måns

Matabele

unread,
Jun 11, 2016, 2:16:02 PM6/11/16
to TiddlyWiki
Hi Mans

This kind of conditional can be fairly simply achieved using the SetWidget -- the widget will choose either a 'value' or an 'emptyValue' depending upon the output of the filter expression.

<$set name="myVariable" filter="[all[current]field:gender[male]]" value="It's male" emptyValue="It's not male">
<$text text=<<myVariable>>/>
</$set>

regards

Måns

unread,
Jun 11, 2016, 5:42:12 PM6/11/16
to tiddl...@googlegroups.com
Hi Matabele

Thank you very much :-)

I don't quite understand how to use the "myVariable" bit? - or get the idea behind "emptyValue" as opposed to writing: filter="[all[current]field:gender[]]" value="Missing value for gender"?  - therefore I had to create a very long tiddler to get 12 simple macros:

Tiddler name: Macros for he_she_He_She_him_her_Him_Her_his_her_His_Her

\define he()
<$set name="myVariable" filter="[all[current]field:gender[male]]" value="he" emptyValue="">
<$text text=<<myVariable>>/>
<$set name="myVariable" filter="[all[current]field:gender[female]]" value="she" emptyValue="">
<$text text=<<myVariable>>/>
<$set name="myVariable" filter="[all[current]field:gender[]]" value="Missing value for gender" emptyValue="">
<$text text=<<myVariable>>/>
</$set>
</$set>
</$set>
\end
\define He()
<$set name="myVariable" filter="[all[current]field:gender[male]]" value="He" emptyValue="">
<$text text=<<myVariable>>/>
<$set name="myVariable" filter="[all[current]field:gender[female]]" value="She" emptyValue="">
<$text text=<<myVariable>>/>
</$set>
</$set>
\end
\define she()
<$set name="myVariable" filter="[all[current]field:gender[male]]" value="he" emptyValue="">
<$text text=<<myVariable>>/>
<$set name="myVariable" filter="[all[current]field:gender[female]]" value="she" emptyValue="">
<$text text=<<myVariable>>/>
</$set>
</$set>
\end
\define She()
<$set name="myVariable" filter="[all[current]field:gender[male]]" value="He" emptyValue="">
<$text text=<<myVariable>>/>
<$set name="myVariable" filter="[all[current]field:gender[female]]" value="She" emptyValue="">
<$text text=<<myVariable>>/>
</$set>
</$set>
\end

\define him()
<$set name="myVariable" filter="[all[current]field:gender[male]]" value="him" emptyValue="">
<$text text=<<myVariable>>/>
<$set name="myVariable" filter="[all[current]field:gender[female]]" value="her" emptyValue="">
<$text text=<<myVariable>>/>
</$set>
</$set>
\end
\define Him()
<$set name="myVariable" filter="[all[current]field:gender[male]]" value="Him" emptyValue="">
<$text text=<<myVariable>>/>
<$set name="myVariable" filter="[all[current]field:gender[female]]" value="Her" emptyValue="">
<$text text=<<myVariable>>/>
</$set>
</$set>
\end
\define her()
<$set name="myVariable" filter="[all[current]field:gender[male]]" value="him" emptyValue="">
<$text text=<<myVariable>>/>
<$set name="myVariable" filter="[all[current]field:gender[female]]" value="her" emptyValue="">
<$text text=<<myVariable>>/>
</$set>
</$set>
\end
\define Her()
<$set name="myVariable" filter="[all[current]field:gender[male]]" value="Him" emptyValue="">
<$text text=<<myVariable>>/>
<$set name="myVariable" filter="[all[current]field:gender[female]]" value="Her" emptyValue="">
<$text text=<<myVariable>>/>
</$set>
</$set>
\end

\define his()
<$set name="myVariable" filter="[all[current]field:gender[male]]" value="his" emptyValue="">
<$text text=<<myVariable>>/>
<$set name="myVariable" filter="[all[current]field:gender[female]]" value="her" emptyValue="">
<$text text=<<myVariable>>/>
</$set>
</$set>
\end
\define His()
<$set name="myVariable" filter="[all[current]field:gender[male]]" value="His" emptyValue="">
<$text text=<<myVariable>>/>
<$set name="myVariable" filter="[all[current]field:gender[female]]" value="Her" emptyValue="">
<$text text=<<myVariable>>/>
</$set>
</$set>
\end
\define her()
<$set name="myVariable" filter="[all[current]field:gender[male]]" value="his" emptyValue="">
<$text text=<<myVariable>>/>
<$set name="myVariable" filter="[all[current]field:gender[female]]" value="her" emptyValue="">
<$text text=<<myVariable>>/>
</$set>
</$set>
\end
\define Her()
<$set name="myVariable" filter="[all[current]field:gender[male]]" value="His" emptyValue="">
<$text text=<<myVariable>>/>
<$set name="myVariable" filter="[all[current]field:gender[female]]" value="Her" emptyValue="">
<$text text=<<myVariable>>/>
</$set>
</$set>
\end

{{||FakeRadio}}
<<he>>
<<She>>
<<his>>

"FakeRadio" tiddler:


<$reveal type="match" state="!!gender" text="">
<$button set="!!gender" setTo="male" class='tc-btn-invisible'>
<input type=radio/></$button>  Choose Boy/girl</$reveal>
<$reveal type="match" state="!!gender" text="female">
<$button set="!!gender" setTo="" class='tc-btn-invisible'>
<input type=radio checked/></$button>  Girl</$reveal>

<$reveal type="match" state="!!gender" text="male">
<$button set="!!gender" setTo="female" class='tc-btn-invisible'>
<input type=radio checked/></$button>  Boy</$reveal><$reveal type="match" state="!!gender" text="">

I guess there must be a more simple way to do this - if you understand <<myVariable>> and how to exploit the value variations?

Cheers Måns Mårtensson

Måns

unread,
Jun 11, 2016, 7:03:56 PM6/11/16
to TiddlyWiki
<$reveal type="match" state="!!gender" text="">
<$button set="!!gender" setTo="male" class='tc-btn-invisible'>
<input type=radio/></$button>  Choose Boy/girl/pige</$reveal>
<$reveal type="match" state="!!gender" text="female">
<$button set="!!gender" setTo="" class='tc-btn-invisible'>
<input type=radio checked/></$button>  Girl</$reveal>

<$reveal type="match" state="!!gender" text="male">
<$button set="!!gender" setTo="female" class='tc-btn-invisible'>
<input type=radio checked/></$button>  Boy</$reveal><$reveal type="match" state="!!gender" text="">
Reply all
Reply to author
Forward
0 new messages