Difference between revisions of "Template:Qif/doc"

From ISFDB
Jump to navigation Jump to search
(doc page)
 
 
(12 intermediate revisions by the same user not shown)
Line 6: Line 6:
 
*This template also has undefined behaviour, if ''any'' parameter (be it named or unnamed) that is different from '''test''', '''then''' or '''else''' is defined when calling the template.
 
*This template also has undefined behaviour, if ''any'' parameter (be it named or unnamed) that is different from '''test''', '''then''' or '''else''' is defined when calling the template.
  
Note that {{Tlx|qif}} does '''not''' work when subst'ed (like {{Tlx|ifndef}}, the '''then''' part alone as in {{Tlx|ifdef}} can be substituted).  
+
Note that {{Tl|qif}} does '''not''' work when subst'ed (like {{Tl|ifndef}}, the '''then''' part alone as in {{Tl|ifdef}} can be substituted).  
Of course it's [[m:Help:Parameter_default|impossible]] to use vertical bars in parameter values directly, use either <tt>&amp;#124;</tt> or [[:Template:!]] - the latter is only relevant for Wiki table delimiters.
+
Of course it's [[Help:Parameter_default|impossible]] to use vertical bars in parameter values directly, use either <tt>&amp;#124;</tt> or [[:Template:!]] - the latter is only relevant for Wiki table delimiters.
 
 
Wikipedia CTO Brion VIBBER has expressed [[Wikipedia_talk:Avoid_using_meta-templates/Archive_3#What_I_need_from_you|support]] to implement the functionality of qif into MediaWiki. So qif should not be viewed as definitive solution.
 
  
 
== Usage ==
 
== Usage ==
Line 28: Line 26:
 
}}
 
}}
 
</pre>
 
</pre>
 +
 +
Note that if you are using Qif inside a template to determine if a template parameter has been defined with a non-empty value, you should test the parameter with an emnpty default.
 +
 +
Example:
 +
 +
<pre><nowiki>
 +
{{qif
 +
  |test={{{Check|}}}
 +
  |then=Present
 +
  |else=Absent
 +
}}
 +
</nowiki></pre>
 +
 +
Inside a template defination, this will return "Present" if the enclosing template has a parameter "Check" with a non-empty value, and "Absent" otherwise.
  
 
== Example ==
 
== Example ==
{| class="wikitable"
+
{| border="1" cellspacing="1" cellpadding="2"
 
!Code
 
!Code
 
!Result
 
!Result
Line 83: Line 95:
 
|}
 
|}
  
 +
=== Caveats ===
 +
 +
In templates the characters "<tt>'''='''</tt>" (&amp;#61;) and "<tt>'''|'''</tt>" (&amp;#124;) cannot be used as is in parameters.
 +
The ''numeric character references'' &amp;#61; and &amp;#124; are often good enough, but for Wiki and XHTML markup the literal
 +
characters are required:
 +
# For <tt>'''|'''</tt> <span class="plainlinks">[[template:!]] (<small>[http://meta.wikimedia.org/w/index.php?title=Template:%21&action=edit edit]•[[template talk:!|talk]]•[http://meta.wikimedia.org/w/index.php?title=Special:Whatlinkshere/template:%21&limit=500 links]•[http://meta.wikimedia.org/w/index.php?title=Template:%21&action=history history]</small>)</span> offers a workaround.
 +
# For <tt>'''='''</tt> the template parameter mechanism allows <nowiki> {{ifdef|1|2=ok=yes}} resulting in "ok=yes" instead of {{ifdef|1|bad=idea}} resulting in "{{{2}}} "</nowiki>
 +
Substitution works only for {{Tlx|ifdef}}, but '''not''' for {{Tlx|ifndef}} or {{Tlx|qif}}.
  
 
==Source==
 
==Source==
This documentation (or its inital version, it may have been edited here since) is copied from [[Wikipedia:Template talk:Qif]], under the [[Wikippedia:GFDL|GNU Free documentation licensce]] (which all wikipedia text is released under). See that page amnt it's archives for related information and caveats.
+
This documentation (or its inital version, it may have been edited here since) is copied from [[Wikipedia:Template talk:Qif]], under the [[Wikipedia:GNU Free Documentation License|GNU Free Documentation License]] (GFDL) (under which all wikipedia text is released). See that page and its archives for related information and caveats.
 +
 
 +
The template itself was copied from [[Wikipedia:Template:Qif]], and then modified. The template was also released under the GFDL.
 +
 
 +
See also: [[Wikipedia:Wikipedia:ParserFunction precursors]]
 +
 
 +
==Applies to==
 +
This is the documentation page for [[:Template:Qif]], transcluded from [[:Template:Qif/doc]].
 +
 
 +
Note that {{tl|Qif}} is protected, as a high risk template.

Latest revision as of 17:04, 13 June 2009

Purpose and Function

Provides if then else functionality.

  • Parameter else is optional.
  • This template has undefined behaviour, if parameter test or then (or both) are missing.
  • This template also has undefined behaviour, if any parameter (be it named or unnamed) that is different from test, then or else is defined when calling the template.

Note that {{qif}} does not work when subst'ed (like {{ifndef}}, the then part alone as in {{ifdef}} can be substituted). Of course it's impossible to use vertical bars in parameter values directly, use either &#124; or Template:! - the latter is only relevant for Wiki table delimiters.

Usage

{{qif
  |test=VARIABLE_OR_PARAMETER_TO_TEST
  |then=code if 'test' is not empty
  |else=code if 'test' is empty
}}

Parameter else is optional. So you may also do:

{{qif
  |test=VARIABLE_OR_PARAMETER_TO_TEST
  |then=code if 'test' is not empty
}}

Note that if you are using Qif inside a template to determine if a template parameter has been defined with a non-empty value, you should test the parameter with an emnpty default.

Example:

{{qif
  |test={{{Check|}}}
  |then=Present
  |else=Absent
}}

Inside a template defination, this will return "Present" if the enclosing template has a parameter "Check" with a non-empty value, and "Absent" otherwise.

Example

Code Result
{{qif
  |test={{boolne|foo|bar}}
  |then=true
  |else=false
}}

true

{{qif
  |test={{booleq|foo|bar}}
  |then=true
  |else=false
}}

false

{{qif
  |test=
  |then=bar
}}
{{qif
  |test=foo
  |then=bar
}}

bar

Caveats

In templates the characters "=" (&#61;) and "|" (&#124;) cannot be used as is in parameters. The numeric character references &#61; and &#124; are often good enough, but for Wiki and XHTML markup the literal characters are required:

  1. For | template:! (edittalklinkshistory) offers a workaround.
  2. For = the template parameter mechanism allows {{ifdef|1|2=ok=yes}} resulting in "ok=yes" instead of {{ifdef|1|bad=idea}} resulting in "{{{2}}} "

Substitution works only for {{ifdef, but not for {{ifndef or {{qif.

Source

This documentation (or its inital version, it may have been edited here since) is copied from Wikipedia:Template talk:Qif, under the GNU Free Documentation License (GFDL) (under which all wikipedia text is released). See that page and its archives for related information and caveats.

The template itself was copied from Wikipedia:Template:Qif, and then modified. The template was also released under the GFDL.

See also: Wikipedia:Wikipedia:ParserFunction precursors

Applies to

This is the documentation page for Template:Qif, transcluded from Template:Qif/doc.

Note that {{Qif}} is protected, as a high risk template.