All,
I can see value in a pragma style if then else, it makes writing macro style solutions nice but for many structures we are likely to have case where we want the if then else structures throughout the wiki text.
It seems to me the quickest path is to provide the following; one could reuse the list widget code or simply provide an alias;
- Alias for $list of $if (may actually use the exact same code as $list)
- Allow the “template” parameter to have an alias “then” and accept inline text or a variable/macro name eg
then=<<macro>>
- Allow the “emptyMessage” to have an alias “else” - it already accepts litterals, templates or macros.
For example in the following example which is already a reasonable case structure.
Using $if would look like this;
<$set name=input filter="[<input>]uppercase[]]">
<$if filter="[<input>match[A]then[Another]]" then="true"></$if>
<$if filter="[<input>match[B]then[Best]]" then="true"></$if>
<$if filter="[<input>match[C]then[Caught]]" then="true"></$if>
<$if filter="[<input>match[D]then[Default]]" then="true"></$if>
</$set>
However the advantage if reusing the $list widget is we gain a lot more we can code “inline”
Or a more complete nested if
<$if filter="[<input>match[A]then[Another]]" then="""
A true wikitext"""
else="""
Not A Wiki text
<$if filter="[<input>match[B]then[Best]]" then={{btrue}} else="Not A or B"></$if>
"""
></$if>
But the key features of this solution are
- It permits nesting via literal, variable or transclusion
- You can display intermediate results eg: “Not A Wiki text”
- You can have multiple $if throughout the wikitext without needing to follow macro definitions.
- $if implies the result is true or false, however we could code “if any” and “if for each”
- A designer approach to use $if when the result is intended to be true false would help readability eg;
<$if filter="[{$:/config/debug-mode}match[yes]]" then="Show in debug mode"/>
OR
<$if filter="[{$:/config/debug-mode}match[yes]]">
Show in debug mode
</$if>
OR
<$if filter="[{$:/config/debug-mode}match[yes]]" else=<<toggle-debug>> >
Show in debug mode
</$if>
The above is quicker and clearer when using filters in what would be the list widget simply to display conditional content. This is because the result is true or false not a list, the $if suggests it is not a list, although we have available the full $list widget features.