Difference between revisions of "User:Ericb/If"

From MHWiki
(another new template)
 
m (link to live version)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
<noinclude>A conditional template.  The first argument cannot be "use=".  If the first argument contains any text, then we end up calling the <nowiki>{{Use}}</nowiki> template with two arguments, one named "use" with our second argument as its value, and the other will be unnamed or have an unrelated name, so the overall expansion is our one use of the name "use" - our second argument.  But if the first argument is empty (or missing), then we provide a default expansion such that we end up using the <nowiki>{{Use}}</nowiki> template with use= specified twice, and the last use wins, giving the overall expansion of our third argument.
+
<noinclude>''This page was my playground before creating [[Template:If]]''
  
That is, I implemented {{#if:test|if text|if empty}}, with a slightly different syntax:<br/>
+
A conditional template.  The first argument cannot start with "=".  If the first argument contains any text, then this ends up calling the <nowiki>{{Use}}</nowiki> template with two arguments, one named "use" with the original second argument as its value, and the other will have an unrelated name, so the overall expansion is the one use of the name "use" - the second argument.  But if the first argument is empty (or missing), then this ends up using the <nowiki>{{Use}}</nowiki> template with use= specified twice, and the last use wins, giving the overall expansion of the third argument.
<nowiki>{{if|test|if text|if empty}}</nowiki></noinclude>
+
 
<includeonly>{{User:Ericb/Use|use={{{2|}}}|{{{1|use=}}}{{{3|}}}}}</includeonly>
+
That is, this template is an alternative implementation of {{#if:test|if text|if empty}}, with a slightly different syntax:<br/>
 +
<nowiki>{{if|test|if text|if empty}}</nowiki>
 +
</noinclude><includeonly>{{User:Ericb/Use|use={{{2|}}}|use{{{1|}}}={{{3|}}}}}</includeonly>

Latest revision as of 00:48, 26 October 2011

This page was my playground before creating Template:If

A conditional template. The first argument cannot start with "=". If the first argument contains any text, then this ends up calling the {{Use}} template with two arguments, one named "use" with the original second argument as its value, and the other will have an unrelated name, so the overall expansion is the one use of the name "use" - the second argument. But if the first argument is empty (or missing), then this ends up using the {{Use}} template with use= specified twice, and the last use wins, giving the overall expansion of the third argument.

That is, this template is an alternative implementation of {{#if:test|if text|if empty}}, with a slightly different syntax:
{{if|test|if text|if empty}}