User:Gorgon/Sandbox/Sandbox Charlie: Difference between revisions

From Avlis Wiki
Jump to navigation Jump to search
m (Always forgetting something...)
m (Test version of emplate:Ifparadef (If parameter defined).)
Line 1: Line 1:
{{#switch:
{{#switch: {{{1|¬}}}
  {{lc:              <!--Lower case the result-->
|   = {{{4| {{{2|}}} }}} <!-- Defined, empty. Must come before {{{1|}}}, since " " = " " -->
    <!--If no or empty "demospace" parameter then detect namespace-->
| ¬ = {{{3|}}}           <!-- Not defined. Must come before {{{1|}}}, since ¬ = ¬ -->
    {{#if:{{{demospace|}}}
| {{{1|}}} = {{{2|}}}   <!-- Defined, not empty. {{{1}}} = {{{1}}} -->
    | {{{demospace}}}
}}<noinclude>
    | {{#if:{{{page|}}}
      | <!--Detect the namespace in the "page" parameter-->
        {{#ifeq:{{NAMESPACE:{{{page}}} }}|{{TALKSPACE:{{{page}}} }}
        | talk
        | {{SUBJECTSPACE:{{{page}}} }}
        }}
      | <!--No "demospace" or "page" parameters, so detect actual namespace-->
        {{#ifeq:{{NAMESPACE}}|{{TALKSPACE}}
        | talk
        | {{SUBJECTSPACE}}
        }}
      }}
    }}
  }}
<!-- Only one of the lines below will be executed -->
<!-- Respecting empty parameters on purpose -->
| main        <!--"demospace=main" or {{SUBJECTSPACE}}={{ns:0}}=""-->
|           = {{{main| {{{other|}}} }}}
| talk      = {{{talk| {{{other|}}} }}}
| user      = {{{user| {{{other|}}} }}}
| avlis wiki = {{{avlis wiki| {{{other|}}} }}}
| file
| image      = {{{file| {{{image| {{{other|}}} }}} }}}
| mediawiki  = {{{mediawiki| {{{other|}}} }}}
| template  = {{{template| {{{other|}}} }}}
| help      = {{{help| {{{other|}}} }}}
| category  = {{{category| {{{other|}}} }}}
| other
| #default  = {{{other|}}<!--"demospace=other" or a new namespace-->


}}<!--End switch--><noinclude>


== Template:Ifparadef (If parameter defined) ==


== Template:Ns detect (Namespace detect) ==
This template is based on [[Wikipedia:Template:Ifparadef | Template:Ifparadef]].


This template is based on <span class="plainlinks">[http://www.mediawiki.org/wiki/Template:Namespace_detect Template:Namespace detect]</span>.
It uses the original markup. The documentation below was copied to this template, since we do not use [[Wikipedia:Wikipedia:Template_documentation#How_to_create_a_documentation_subpage | documentation sub-pages]]. Most of the [[Wikipedia:Main_Page | Wikipedia]] specific information, links and sub-templates have either been removed, or modified for the Avlis wiki.


It uses the original markup, modified for Avlis wiki namespaces. The documentation below was copied to this template, since we do not use [[Wikipedia:Wikipedia:Template_documentation#How_to_create_a_documentation_subpage | documentation sub-pages]]. It has also been modified for Avlis namespaces, and most of the <span class="plainlinks">[http://www.mediawiki.org/wiki/MediaWiki MediaWiki]</span> specific information, links and sub-templates have either been removed, or modified for the Avlis wiki. It has been reformatted, and several sections modified for improved clarity.
See the [[Wikipedia:Template:Ifparadef/doc | original template documentation]] for further details.
 
See the <span class="plainlinks">[http://www.mediawiki.org/wiki/Template:Namespace_detect/doc original template documentation]</span> for further details.




== Template documentation ==
== Template documentation ==


This is the '''<nowiki>{{ns detect}}</nowiki>''' (Namespace detect) meta-template.
This template is used to test if a parameter is defined; thus, it should only be directly used on other templates.
 
It helps other templates detect what type of namespace they are used in.
 
It detects and groups all of the different <span class="plainlinks">[http://wiki.avlis.org/mediawiki/api.php?action=query&meta=siteinfo&siprop=namespaces namespaces]</span> used on the Avlis wiki into several types:
 
:'''main''' = Main/article namespace, as in normal Avlis wiki articles.
:'''talk''' = Any talk namespace, such as page names that start with "Talk:", "User talk:", "File talk:" and so on.
:'''user, avlis wiki, file, mediawiki, template, help, and category''' = The other namespaces, except for talk namespace pages.
:'''other''' = Any namespaces that were not specified as a parameter to the template. ''See the '''Note:''' in the "[[#Parameters | Parameters]]" section below.''
 
''For backwards compatibility, this template also understands the old name '''image''' for '''file'''. But using '''image''' is now deprecated.''




=== Usage ===
=== Usage ===


'''Note:''' The following examples use multiple lines for improved readability. All of them can be written as single lines as well.
This template accepts up to four unnamed parameters.
 
* Standard functionality: <code><nowiki>{{ifparadef | {{{parameter_name | ¬}}} | Defined | Not defined}}</nowiki></code>
E.g., <code><nowiki>{{ns detect | main = Article text | talk = Talk page text | other = Other pages text}}</nowiki></code> for the first example below.
* Extended functionality: <code><nowiki>{{ifparadef | {{{parameter_name | ¬}}} | Defined, not empty | Not defined | Defined, empty}}</nowiki></code>
 
 
This template takes one or more parameters, named after the different namespace types listed above. Like this:
 
<pre style="white-space: pre">
{{ns detect
| main  = Article text
| talk  = Talk page text
| other = Other pages text
}}
</pre>
 
If the template is in a main (article) namespace page, it will return this:
 
:{{<!-- ns detect -->User:Gorgon/Sandbox/Sandbox Charlie| demospace=main
| main  = Article text
| talk  = Talk page text
| other = Other pages text
}}
 
If the template is used in any other namespace page than a main (article), or a talk page, it will return this:
 
:{{<!-- ns detect -->User:Gorgon/Sandbox/Sandbox Charlie
| main  = Article text
| talk  = Talk page text
| other = Other pages text
}}
 
 
The example above made the template return something for all other namespace page types. But if we don't use the '''other''' parameter, or leave it empty, then it will not return anything for the other namespace page types. Like this:
 
<pre style="white-space: pre">
{{ns detect
| file    = File page text
| category = Category page text
| other    =
}}
</pre>
 
In any pages, other than file and category namespace pages, the code above will render nothing.
<!-- Do not remove this one. It is supposed to render nothing, but we have it here for testing purposes. -->
:{{<!-- ns detect -->User:Gorgon/Sandbox/Sandbox Charlie
| file    = File page text
| category = Category page text
| other    =
}}
 
 
By using an empty parameter, you can make it so the template doesn't render anything for a specific namespace type page. Like this:
 
<pre style="white-space: pre">
{{ns detect
| main  =
| other = Other pages text
}}
</pre>
 
The code above will render nothing when in main (article) namespace pages, but will return this when in other namespace type pages:
 
:{{<!-- ns detect -->User:Gorgon/Sandbox/Sandbox Charlie
| main  =
| other = Other pages text
}}
 
 
As an extended example of empty parameter usage, if you need to assign the same value to more than one namespace type parameter as a result, and the value is a larger block of code, it is inefficient to duplicate the same code for multiple parameter values. Instead, you can use empty parameters to return nothing for namespace type pages that you don't want the value used in (all except the ones you need), and then use the '''other''' parameter value to return the result of your block of code for the namespace type pages that you do want it in. Like this:


<pre style="white-space: pre">
The first parameter, which is required, is the name of the parameter to be tested. It must be formatted as <code><nowiki>{{{parameter_name | ¬}}}</nowiki></code>, '''with the "¬"''', otherwise the template will not work correctly (see the [[#Examples | Examples]] section below for examples with and without the "¬").
{{ns detect
| talk = | avlis wiki = | file = | mediawiki = | help = | category =
| other = {{{|Result of large, multi-line block of code.}}}
}}
</pre>
For the result below, when in main (article), user and template namespace pages, the code above will use the '''other''' parameter value, since those 3 namespace types weren't included as parameters. When in all other namespace type pages, nothing is returned, since they all have empty values:


:{{<!-- ns detect -->User:Gorgon/Sandbox/Sandbox Charlie
The second parameter is the text to display if the tested parameter is defined. If the fourth parameter is also used, the second parameter is the text displayed when the tested parameter is defined and not empty.
| talk = | avlis wiki = | file = | mediawiki = | help = | category =
| other = {{{|Result of large, multi-line block of code.}}}
}}


The third parameter is the text to display if the tested parameter is not defined.


=== Demospace and page ===
The fourth parameter is the text to display if the tested parameter is defined and empty (or if it contains only whitespace). If this parameter is omitted, only one defined test is performed, and the contents (or default) of the second parameter are used as long as the tested parameter is defined.


For testing and demonstration purposes, this template can take two parameters, named '''demospace''' and '''page'''. Only assign a value to one of these in your template. If both have values assigned, then only the '''demospace''' parameter will be used.
This template uses "¬" to test for a defined parameter; the template cannot detect when a literal "¬" is passed as input from a final deployment (such as an article), and will give incorrect results in such cases. If you need to handle that case too, then see <nowiki>{{</nowiki>[[Wikipedia:Template:ifparadef full |ifparadef full]]<nowiki>}}</nowiki>.


'''Demospace''' understands any of the namespace type names used by this template, including the '''other''' namespace type. It tells the template to behave like it is in a specific namespace type page. Like this:


<pre style="white-space: pre">
==== Examples ====
{{ns detect
| main      = Article text
| other    = Other pages text
| demospace = main
}}
</pre>


No matter what namespace the code above is used in, it will return this:
{| class="wikitable" style="width: 98%;"
|+ Normal use
|-
! Code !! Result
|-
| <code><nowiki>{{ifparadef | {{{parameter_name | ¬}}} | Defined | Not defined}}</nowiki></code>
| {{<!-- ifparadef -->User:Gorgon/Sandbox/Sandbox Charlie | {{{parameter_name | ¬}}} | Defined | Not defined}}
|-
| <code><nowiki>{{ifparadef | {{{parameter_name | Some text}}} | Defined | Not defined}}</nowiki></code>
| {{<!-- ifparadef -->User:Gorgon/Sandbox/Sandbox Charlie | {{{parameter_name | Some text}}} | Defined | Not defined}}
|-
| <code><nowiki>{{ifparadef | Some text | Defined | Not defined}}</nowiki></code>
| {{<!-- ifparadef -->User:Gorgon/Sandbox/Sandbox Charlie | Some text | Defined | Not defined}}
|-
| <code><nowiki>{{ifparadef |  | Defined | Not defined}}</nowiki></code>
| {{<!-- ifparadef -->User:Gorgon/Sandbox/Sandbox Charlie |  | Defined | Not defined}}
|-
|}
{| class="wikitable" style="width: 98%;"
|+ Extended use (with fourth parameter)
|-
! Code !! Result
|-
| <code><nowiki>{{ifparadef | {{{parameter_name | }}} | Defined, not empty | Not defined | Defined, empty}}</nowiki></code>
| {{<!-- ifparadef -->User:Gorgon/Sandbox/Sandbox Charlie | {{{parameter_name | }}} | Defined, not empty | Not defined | Defined, empty}}
|-
| <code><nowiki>{{ifparadef | {{{parameter_name | Some text}}} | Defined, not empty | Not defined | Defined, empty}}</nowiki></code>
| {{<!-- ifparadef -->User:Gorgon/Sandbox/Sandbox Charlie | {{{parameter_name | Some text}}} | Defined, not empty | Not defined | Defined, empty}}
|-
| <code><nowiki>{{ifparadef | {{{parameter_name | ¬}}} | Defined, not empty | Not defined | Defined, empty}}</nowiki></code>
| {{<!-- ifparadef -->User:Gorgon/Sandbox/Sandbox Charlie | {{{parameter_name | ¬}}} | Defined, not empty | Not defined | Defined, empty}}
|-
| <code><nowiki>{{ifparadef | Some text | Defined, not empty | Not defined | Defined, empty}}</nowiki></code>
| {{<!-- ifparadef -->User:Gorgon/Sandbox/Sandbox Charlie | Some text | Defined, not empty | Not defined | Defined, empty}}
|-
| <code><nowiki>{{ifparadef |  | Defined, not empty | Not defined | Defined, empty}}</nowiki></code>
| {{<!-- ifparadef -->User:Gorgon/Sandbox/Sandbox Charlie |  | Defined, not empty | Not defined | Defined, empty}}
|}
{| class="wikitable" style="width: 98%;"
|+ <span style="color:red">'''Incorrect'''</span> <nowiki>{{ifparadef}}</nowiki> usage in a template named <nowiki>{{ifparadef/test}}</nowiki>, containing: <code><nowiki>{{ifparadef | {{{parameter | }}} | Defined | Not defined}}</nowiki></code>
|-
! Code !! Result
|-
| <code><nowiki>{{ifparadef/test | parameter = Some text}}</nowiki></code>
| {{<!-- ifparadef -->User:Gorgon/Sandbox/Sandbox Charlie | Some text | Defined | Not defined}}
|-
| <code><nowiki>{{ifparadef/test | parameter = }}</nowiki></code>
| {{<!-- ifparadef -->User:Gorgon/Sandbox/Sandbox Charlie | | Defined | Not defined}}
|-
| <code><nowiki>{{ifparadef/test}}</nowiki></code>
| {{<!-- ifparadef -->User:Gorgon/Sandbox/Sandbox Charlie | | Defined | Not defined}}
|}
{| class="wikitable" style="width: 98%;"
|+ <span style="color:green">'''Correct'''</span> <nowiki>{{ifparadef}}</nowiki> usage in a template named <nowiki>{{ifparadef/test2}}</nowiki>, containing: <code><nowiki>{{ifparadef | {{{parameter | ¬}}} | Defined | Not defined}}</nowiki></code>
|-
! Code !! Result
|-
| <code><nowiki>{{ifparadef/test2 | parameter = Some text}}</nowiki></code>
| {{<!-- ifparadef -->User:Gorgon/Sandbox/Sandbox Charlie | Some text | Defined | Not defined}}
|-
| <code><nowiki>{{ifparadef/test2 | parameter = }}</nowiki></code>
| {{<!-- ifparadef -->User:Gorgon/Sandbox/Sandbox Charlie | | Defined | Not defined}}
|-
| <code><nowiki>{{ifparadef/test2}}</nowiki></code>
| {{<!-- ifparadef -->User:Gorgon/Sandbox/Sandbox Charlie | ¬ | Defined | Not defined}}
|}
{| class="wikitable" style="width: 98%;"
|+ <span style="color:red">'''Incorrect'''</span> <nowiki>{{ifparadef}}</nowiki> usage in a template named <nowiki>{{ifparadef/test3}}</nowiki>, containing: <code><nowiki>{{ifparadef | {{{parameter | }}} | Defined, not empty | Not defined | Defined, empty}}</nowiki></code>
|-
! Code !! Result
|-
| <code><nowiki>{{ifparadef/test3 | parameter = Some text}}</nowiki></code>
| {{<!-- ifparadef -->User:Gorgon/Sandbox/Sandbox Charlie | Some text | Defined, not empty | Not defined | Defined, empty}}
|-
| <code><nowiki>{{ifparadef/test3 | parameter = }}</nowiki></code>
| {{<!-- ifparadef -->User:Gorgon/Sandbox/Sandbox Charlie | | Defined, not empty | Not defined | Defined, empty}}
|-
| <code><nowiki>{{ifparadef/test3}}</nowiki></code>
| {{<!-- ifparadef -->User:Gorgon/Sandbox/Sandbox Charlie | | Defined, not empty | Not defined | Defined, empty}}
|}
{| class="wikitable" style="width: 98%;"
|+ <span style="color:green">'''Correct'''</span> <nowiki>{{ifparadef}}</nowiki> usage in a template named <nowiki>{{ifparadef/test4}}</nowiki>, containing: <code><nowiki>{{ifparadef | {{{parameter | ¬}}} | Defined, not empty | Not defined | Defined, empty}}</nowiki></code>
|-
! Code !! Result
|-
| <code><nowiki>{{ifparadef/test4 | parameter = Some text}}</nowiki></code>
| {{<!-- ifparadef -->User:Gorgon/Sandbox/Sandbox Charlie | Some text | Defined, not empty | Not defined | Defined, empty}}
|-
| <code><nowiki>{{ifparadef/test4 | parameter = }}</nowiki></code>
| {{<!-- ifparadef -->User:Gorgon/Sandbox/Sandbox Charlie | | Defined, not empty | Not defined | Defined, empty}}
|-
| <code><nowiki>{{ifparadef/test4}}</nowiki></code>
| {{<!-- ifparadef -->User:Gorgon/Sandbox/Sandbox Charlie | ¬ | Defined, not empty | Not defined | Defined, empty}}
|}


:{{<!-- ns detect -->User:Gorgon/Sandbox/Sandbox Charlie
| main      = Article text
| other    = Other pages text
| demospace = main
}}


=== Hardcoding ===


The '''page''' parameter instead takes a "namespace:pagename" value. It makes this template behave as if rendered in that page's namespace type. The page name doesn't have to be an existing page. Like this:
An alternative to using this meta-template is to hardcode this functionality in your template. Use the code below for standard and extended functionality:


<pre style="white-space: pre">
<pre style="white-space: pre">
{{ns detect
{{#ifeq: {{{parameter_name | ¬}}} | ¬
| user  = User page text
| Not defined.
| other = Other pages text
| Defined. (Empty or has data.)
| page  = User:Example
}}
</pre>
 
No matter what namespace the code above is used in, it will return this:
 
:{{<!-- ns detect -->User:Gorgon/Sandbox/Sandbox Charlie
| user  = User page text
| other = Other pages text
| page  = User:Example
}}
}}


'''Note:''' The value of '''page''' is only used to determine the namespace type of that page. The "pagename" part of the "namespace:pagename" value isn't used for anything, but is required by the '''<nowiki>{{NAMESPACE}}</nowiki>''', '''<nowiki>{{TALKSPACE}}</nowiki>''' and '''<nowiki>{{SUBJECTSPACE}}</nowiki>''' magic words that are used by the '''<nowiki>{{ns detect}}</nowiki>''' template (see: [http://www.mediawiki.org/wiki/Help:Magic_words#Namespaces Help:Magic words#Namespaces]). The '''demospace''' parameter is usually a better choice for setting an alternate namespace type in testing, unless you need to use a "namespace:pagename" value.
{{#switch: {{{parameter_name | ¬}}}
 
| ¬ = Not defined.
 
|   = Defined, empty.
It may be convenient to define the '''demospace''' and/or '''page''' parameters as (optional) named parameters by the page using your template, and send them on to the '''<nowiki>{{ns detect}}</nowiki>''' template.
| #default = Defined, not empty.
 
E.g., A sandbox page in a userspace <code>User:Example/sandbox</code> for testing your template '''<nowiki>{{mytemplate}}</nowiki>''' as if it was in the main namespace:
 
:'''Code in User:Example/sandbox:''' <code><nowiki>{{mytemplate | demospace = main}}</nowiki></code> or <code><nowiki>{{mytemplate | page = Example page}}</nowiki></code>
 
:'''Note:''' There is no "Main:" prefix on pages in the main namespace, so only the <code>Example page</code> "pagename" is required.
 
:''This also allows testing other namespaces types from the same sandbox page by changing the parameter values, even using preview mode.''
 
Then in your '''<nowiki>{{mytemplate}}</nowiki>''' template, do like this:
 
<pre style="white-space: pre">
{{ns detect
| main      = Article text
| other    = Other pages text
| demospace = {{{demospace|}}}
| page      = {{{page|}}}
}}
}}
</pre>
</pre>


These parameters will be used by the template only if defined by the page using your template. If both the '''demospace''' and '''page''' parameters are empty, or undefined, then the template will detect namespace types as usual for the page. As described above, if both the '''demospace''' and '''page''' parameters have values assigned, then only the '''demospace''' parameter will be used.
=== Parameters ===


List of all parameters:
For code that works with any input (detects "¬" as defined, not empty), see [[Wikipedia:Template:ifparadef full#Hardcoding | Template:Ifparadef full#Hardcoding]]. Use the code below for standard and extended functionality:


<pre style="white-space: pre">
<pre style="white-space: pre-wrap">
{{ns detect
{{#ifeq: {{{parameter_name | x}}} | {{{parameter_name | y}}}
| main      =
| Defined. (Empty or has data.)
| talk      =
| Not defined.
| user      =
| avlis wiki =
| file      =
| mediawiki  =
| template  =
| help      =
| category  =
| other      =
| demospace  = {{{demospace|}}}
              One of: main, talk, user, avlis wiki,
                      file, mediawiki, template,
                      help, category, other
| page      = {{{page|}}} E.g., User:Example
}}
}}
</pre>
'''Note:''' Empty values for the '''main''' through '''category''' parameters are different than not including (defining) them. An undefined parameter (i.e, one you do not include in your template usage) will use the result of the '''other''' parameter when in that namespace type. Any that are defined, but not assigned a value (i.e, included in the template usage, but nothing after the = ) will render nothing when used in that namespace type.


=== Technical details ===
{{#switch: {{{parameter_name | x}}}{{{parameter_name | y}}}
| xy = Not defined.
|    = Defined, empty.
| #default = Defined, not empty.
}}</pre>


If you intend to use <span class="plainlinks">[http://www.mediawiki.org/wiki/Help:Tables wikitables]</span> as parameter values in this template, then you need to know this:


<span class="plainlinks">[http://www.mediawiki.org/wiki/Help:Templates Templates]</span> have a problem handling parameter data that contains pipes "<code>|</code>", unless the pipe is inside another template <code><nowiki>{{name|param1}}</nowiki></code>, or inside a piped link <code><nowiki>[[Help:Template|help]]</nowiki></code>. Therefore templates can not handle wikitables as input, unless you escape them by using the '''<nowiki>{{!}}</nowiki>''' magic word (parser function - see: <span class="plainlinks">[http://www.mediawiki.org/wiki/Help:Magic_words#Other Help:Magic words#Other]</span>). This makes it hard to use wikitables as parameters in templates. Instead, the usual solution is to use [[Wikipedia:Help:HTML_in_wikitext | HTML wikimarkup]] for the table code, which is more robust.
=== See also ===


'''''Note:''' [[Template:!]] functionality was replaced in MediaWiki version 1.24 by the '''<nowiki>{{!}}</nowiki>''' magic word, and the template is ignored when using it.''
* <nowiki>{{</nowiki>[[Wikipedia:Template:ifparadef full |ifparadef full]]<nowiki>}}</nowiki> - Extended version of this template, but works with any input (correctly detects "¬" as defined, not empty).
* <nowiki>{{</nowiki>[[Wikipedia:Template:ifempty |ifempty]]<nowiki>}}</nowiki> - Allows testing of up to four parameters, returning the contents of the first non-empty one.


<!-- [[Category:Templates|{{PAGENAME}}]] --></noinclude>
{{ns detect | template = [[Category:Templates |{{PAGENAME}}]] }}</noinclude>

Revision as of 20:34, 2 February 2017


Template:Ifparadef (If parameter defined)

This template is based on Template:Ifparadef.

It uses the original markup. The documentation below was copied to this template, since we do not use documentation sub-pages. Most of the Wikipedia specific information, links and sub-templates have either been removed, or modified for the Avlis wiki.

See the original template documentation for further details.


Template documentation

This template is used to test if a parameter is defined; thus, it should only be directly used on other templates.


Usage

This template accepts up to four unnamed parameters.

  • Standard functionality: {{ifparadef | {{{parameter_name | ¬}}} | Defined | Not defined}}
  • Extended functionality: {{ifparadef | {{{parameter_name | ¬}}} | Defined, not empty | Not defined | Defined, empty}}

The first parameter, which is required, is the name of the parameter to be tested. It must be formatted as {{{parameter_name | ¬}}}, with the "¬", otherwise the template will not work correctly (see the Examples section below for examples with and without the "¬").

The second parameter is the text to display if the tested parameter is defined. If the fourth parameter is also used, the second parameter is the text displayed when the tested parameter is defined and not empty.

The third parameter is the text to display if the tested parameter is not defined.

The fourth parameter is the text to display if the tested parameter is defined and empty (or if it contains only whitespace). If this parameter is omitted, only one defined test is performed, and the contents (or default) of the second parameter are used as long as the tested parameter is defined.

This template uses "¬" to test for a defined parameter; the template cannot detect when a literal "¬" is passed as input from a final deployment (such as an article), and will give incorrect results in such cases. If you need to handle that case too, then see {{ifparadef full}}.


Examples

Normal use
Code Result
{{ifparadef | {{{parameter_name | ¬}}} | Defined | Not defined}} Not defined
{{ifparadef | {{{parameter_name | Some text}}} | Defined | Not defined}} Defined
{{ifparadef | Some text | Defined | Not defined}} Defined
{{ifparadef | | Defined | Not defined}} Defined
Extended use (with fourth parameter)
Code Result
{{ifparadef | {{{parameter_name | }}} | Defined, not empty | Not defined | Defined, empty}} Defined, empty
{{ifparadef | {{{parameter_name | Some text}}} | Defined, not empty | Not defined | Defined, empty}} Defined, not empty
{{ifparadef | {{{parameter_name | ¬}}} | Defined, not empty | Not defined | Defined, empty}} Not defined
{{ifparadef | Some text | Defined, not empty | Not defined | Defined, empty}} Defined, not empty
{{ifparadef | | Defined, not empty | Not defined | Defined, empty}} Defined, empty
Incorrect {{ifparadef}} usage in a template named {{ifparadef/test}}, containing: {{ifparadef | {{{parameter | }}} | Defined | Not defined}}
Code Result
{{ifparadef/test | parameter = Some text}} Defined
{{ifparadef/test | parameter = }} Defined
{{ifparadef/test}} Defined
Correct {{ifparadef}} usage in a template named {{ifparadef/test2}}, containing: {{ifparadef | {{{parameter | ¬}}} | Defined | Not defined}}
Code Result
{{ifparadef/test2 | parameter = Some text}} Defined
{{ifparadef/test2 | parameter = }} Defined
{{ifparadef/test2}} Not defined
Incorrect {{ifparadef}} usage in a template named {{ifparadef/test3}}, containing: {{ifparadef | {{{parameter | }}} | Defined, not empty | Not defined | Defined, empty}}
Code Result
{{ifparadef/test3 | parameter = Some text}} Defined, not empty
{{ifparadef/test3 | parameter = }} Defined, empty
{{ifparadef/test3}} Defined, empty
Correct {{ifparadef}} usage in a template named {{ifparadef/test4}}, containing: {{ifparadef | {{{parameter | ¬}}} | Defined, not empty | Not defined | Defined, empty}}
Code Result
{{ifparadef/test4 | parameter = Some text}} Defined, not empty
{{ifparadef/test4 | parameter = }} Defined, empty
{{ifparadef/test4}} Not defined


Hardcoding

An alternative to using this meta-template is to hardcode this functionality in your template. Use the code below for standard and extended functionality:

{{#ifeq: {{{parameter_name | ¬}}} | ¬
| Not defined.
| Defined. (Empty or has data.)
}}

{{#switch: {{{parameter_name | ¬}}}
| ¬ = Not defined.
|   = Defined, empty.
| #default = Defined, not empty.
}}


For code that works with any input (detects "¬" as defined, not empty), see Template:Ifparadef full#Hardcoding. Use the code below for standard and extended functionality:

{{#ifeq: {{{parameter_name | x}}} | {{{parameter_name | y}}}
| Defined. (Empty or has data.)
| Not defined.
}}

{{#switch: {{{parameter_name | x}}}{{{parameter_name | y}}}
| xy = Not defined.
|    = Defined, empty.
| #default = Defined, not empty.
}}


See also

  • {{ifparadef full}} - Extended version of this template, but works with any input (correctly detects "¬" as defined, not empty).
  • {{ifempty}} - Allows testing of up to four parameters, returning the contents of the first non-empty one.