Template talk:If defined
Documentation
Purpose
{{if defined}} — If a parameter of variable is defined, call the specified template with specified arguments.
Usage
{{if defined |test=expression to test |call=template to call if test is not empty |1=parameter_1_name=parameter_1_value |2=parameter_2_name=parameter_2_value |... |150=parameter_150_name=parameter_150_value }}
If called within another template, a typical usage is e.g.
- test={{{music|}}}
The result is empty both if the parameter music is undefined, and if it is empty.
Note that if the parameter music is undefined, the text "{{{music}}}" (without "|") is a non-empty text, so in this case the call template is called.
Example
Code | Result |
---|---|
{{if defined |test=hello |call=foreach |1=call=show1 |2=separator=,  |3=1=this |4=2=is |5=3=a |6=4=test }} |
Template:Foreach |
{{if defined |test= |call=foreach |1=call=show1 |2=separator=,  |3=1=this |4=2=is |5=3=a |6=4=test }} |
|
{{if defined |call=foreach |1=call=show1 |2=separator=,  |3=1=this |4=2=is |5=3=a |6=4=test }} |
Template:Foreach |
{{if defined |test=hello |1=call=show1 |2=separator=,  |3=1=this |4=2=is |5=3=a |6=4=test }} |
|
{{if defined |test={{{hello}}} |call=foreach |1=call=show1 |2=separator=,  |3=1=this |4=2=is |5=3=a |6=4=test }} |
Template:Foreach |
See also
- Template:Unless defined
- Template:Tiw - applies "If defined"
- Category:If Templates
History
Copied form Wikipedia: http://en.wikipedia.org/wiki/Template:If_defined