(Apologies if this is a repeat of something already shared)
For whatever reason, I had this itch I needed to scratch: how would I go about setting up a macro that would result in a given “then” wikitext if a condition is true, and a given “else” wikitext if a condition is false.
The macro:
\define IF( condition then else )
<$list filter="""$condition$""">
$then$
</$list>
<$list filter="""$condition$ +[else[no value from condition]] +[match[no value from condition]]""">
$else$
</$list>
\end
A sample macro reference:
<<IF """[<now “dddd”>match[7]]"""
"""Today is Sunday"""
"""Today is not Sunday""">>
4 Likes
Then, if for some reason we have a large number of places where we check to see if today is Sunday, we might like to do this:
Macros:
\define IF( condition then else )
<$list filter="""$condition$""">
$then$
</$list>
<$list filter="""$condition$ +[else[no value from condition]] +[match[no value from condition]]""">
$else$
</$list>
\end
\define ifSunday( then else )
<<IF """[<now "dddd">match[7]]"""
"""$then$"""
"""$else$""">>
\end
<<ifSunday """Today is Sunday"""
"""Today is not Sunday""">>
And then, if you’re an old-timer like me who likes “keywords”:
\define IF( condition kw1 then kw2 else )
<$list filter="""$condition$""">
$then$
</$list>
<$list filter="""$condition$ +[else[no value from condition]] +[match[no value from condition]]""">
$else$
</$list>
\end
<<IF """[<now “dddd”>match[7]]"""
THEN """Today is Sunday"""
ELSE """Today is not Sunday""">>
Yes, but minus the cognitive nickel and diming via semantic symbols.
Square and squiggly brackets and “<” + “>” I’ve gotten to manage with. “<%” and “%>” drive me up the wall. “<$” and “/>”: not a fan, but there really could not be a better choice.