Template:Guide to Unix/Conditional

How to use
The "conditional" template is a hack implementing a type of conditional statement for templates. One calls the template with a conditional tag like. If the condition is "no", then the wiki software substitutes the conditional tag with the no result. For other conditions (such as "yes" or an arbitrary string different from "no") the wiki software substitutes the conditional tag with the yes result.

Here are some example calls:
 * is
 * is
 * is

In the above examples, the conditional tag is useless, because the condition is already known. But the conditional tag can be placed in other templates such as Clink where the condition is not known. This makes that the template behave differently depending on its parameter. In particular, if a parameter to some template is "no" or defaults to "no", then the template can behave differently by passing that parameter in the conditional tag. The conditional tag is a hack for an feature otherwise missing.

How it works
The conditional template consists of a single call to "callno", but with a hack. The hack is very similar to the hack at "ine" on Wikimedia Meta.

Parameters specified twice
Note that "callno" simply calls the template named by the "no" parameter. Also, callno passes template arguments 1 and 2 to the other template. Think of "callno" as a level of indirection.
 * So is the same as

The hack exploits the fact that a parameter can be called twice, which sets the second value.
 * So is not    but

So instead of Template:Userpage we get Template:Stages. Here is the result of : Unix

Using callno to implement conditional
It might seem that "no" is a strange name for a parameter. However, "no" is also the value to parameter 1 of "conditional" that makes conditional behave differently. Look at this call again:
 * is

We can use "callno" to have "conditional" to call "Echo1st" and display text A in most cases, but to call "echo2nd" and display text B at a "no" condition. In the "callno" call, set parameter "no" to "echo1st". This calls "echo1st" in most cases. Then set parameter " " to "Echo2nd". The refers to the parameter 1 of "conditional", which is the condition. If the condition is "no", this replaces the call to "Echo1st" with a call to "Echo2nd". Otherwise, it sets some parameter which "callno" ignores (unless the parameter is 1 or 2, then it remains ignored because "conditional" replaces parameters by setting them after "no" and " ").