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

From Avlis Wiki
Jump to navigation Jump to search
m (Fixing my over-zealous search/replace spacing inside parameter values.)
m (Cleared for something new. Also testing my sandbox "message box", and transclusion of it with test version of Template:sec.)
Line 1: Line 1:
{{#switch: {{{1|¬}}}
{{<!-- sec -->User:Gorgon/Sandbox/Sandbox_Beta | User:Gorgon/Sandbox | 1 }}
|  = {{{4| {{{2|}}} }}} <!-- Defined, empty. Must come before {{{1|}}}, since " " = " " -->
| ¬ = {{{3|}}}          <!-- Not defined. Must come before {{{1|}}}, since ¬ = ¬ -->
| {{{1|}}} = {{{2|}}}    <!-- Defined, not empty. {{{1}}} = {{{1}}} -->
}}<noinclude>
 
 
== Template:Ifparadef (If parameter defined) ==
 
This template is based on [[Wikipedia:Template:Ifparadef | Template:Ifparadef]].
 
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.
 
See the [[Wikipedia:Template:Ifparadef/doc | 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: <code><nowiki>{{ifparadef | {{{parameter_name|¬}}} | Defined | Not defined}}</nowiki></code>
* Extended functionality: <code><nowiki>{{ifparadef | {{{parameter_name|¬}}} | Defined, not empty | Not defined | Defined, empty}}</nowiki></code>
 
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 "¬").
 
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 <nowiki>{{</nowiki>[[Wikipedia:Template:ifparadef full |ifparadef full]]<nowiki>}}</nowiki>.
 
 
==== Examples ====
 
{| 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}}
|}
 
 
=== 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:
 
<pre style="white-space: pre">
{{#ifeq: {{{parameter_name|¬}}} |¬
| Not defined.
| Defined. (Empty or has data.)
}}
 
{{#switch: {{{parameter_name|¬}}}
| ¬ = Not defined.
|  = Defined, empty.
| #default = Defined, not empty.
}}
</pre>
 
 
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-wrap">
{{#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.
}}</pre>
 
 
=== See also ===
 
* <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.
 
{{ns detect | template = [[Category:Templates |{{PAGENAME}}]] }}</noinclude>

Revision as of 05:24, 3 February 2017

This is a user sandbox of Gorgon. A user sandbox is a subpage of the user's user page. It serves as a testing spot and page development space for the user, and is not an Avlis wiki article.