This site is supported by donations to The OEIS Foundation.

Template:Ifdef/doc

From OeisWiki
Jump to: navigation, search

This documentation subpage contains instructions, categories, or other information for Template:Ifdef. [<Edit> Template:Ifdef]

[⧼Purge⧽ Template:Ifdef/doc]

The {{ifdef}}, {{ifdefined}} or {{if defined}} if-then-else template returns {{{2|1}}} if {{{param}}} is defined (it may be the null string or the empty string,) otherwise returns {{{3|0}}}.

The {{is defined}} predicate function template returns 1 (if true) or 0 (if false.)

Not to be confused with what the #if: parser function does

{{#if: test string | value if true | value if false }}

The #if: parser function tests whether the first parameter is 'nonempty' (i.e. neither the null string nor the empty string nor only whitespace characters.) It evaluates to false if the test string is empty or contains only whitespace characters (spaces, newlines, etc.)

(Cf. Help:Extension:ParserFunctionsMediaWiki.org.)

Usage

{{ifdef|param=input parameter (defined or not)| value returned (default 1) if input parameter is defined (may be empty)| value returned (default 0) if input parameter is not defined}}

Examples

Code Result
{{{param}}} {{{param}}}
{{{param|}}}
{{{param|hello}}} hello
{{{param|+}}} +
{{{param|-}}} -
{{ifdef}}
{{ifdef|param = }}
{{ifdef|param = hello}}

The {{ifdef (test)}} template testing template tests whether any of its first eight parameters are defined or not, by calling {{ifdef}}.

Code Result
{{ifdef (test)}}
{{ifdef (test)|one}}
{{ifdef (test)|one|two}}
{{ifdef (test)|one|two|three}}
{{ifdef (test)|one|two|three|four}}

Code

Whitespace is stripped from before and after named parameters (it is not always stripped from unnamed parameters). See http://meta.wikimedia.org/wiki/User:Happy-melon/Templates#Passing_parameters


<!-- Whitespace is stripped from before and after named parameters (it is not always stripped from unnamed parameters.) http://meta.wikimedia.org/wiki/User:Happy-melon/Templates#Passing_parameters --><!--
-->{{#ifeq: {{{param|{{{1|+}}}}}} | {{{param|{{{1|-}}}}}}
| {{{2|1}}} 
| {{{3|0}}} 
}}