Difference between revisions of "Template:Ifdef/doc"

From ISFDB
Jump to navigation Jump to search
 
Line 1: Line 1:
 
==Documentation==
 
==Documentation==
  
<code>{&#123;[[Template:{{PAGENAME}}|{{lcfirst:{{PAGENAME}}}}]]&#125;}</code>
+
<code>{&#123;[[Template:Ifdef|{{lcfirst:Ifdef}}]]&#125;}</code>
 
is a compact variant of {{Tl|Qif}} for simple  
 
is a compact variant of {{Tl|Qif}} for simple  
 
"'''if''' ''defined'' '''then''' ''do''" statements
 
"'''if''' ''defined'' '''then''' ''do''" statements
Line 8: Line 8:
 
=== Usage ===
 
=== Usage ===
  
<code>{&#123;{{PAGENAME}}|value|result&#125;}</code>
+
<code>{&#123;Ifdef|value|result&#125;}</code>
 
yields ''result''&#160; if ''value''&#160; isn't blank.
 
yields ''result''&#160; if ''value''&#160; isn't blank.
  
Line 26: Line 26:
 
| '''Result'''
 
| '''Result'''
 
|-
 
|-
| valign="top" | <code>1 {&#123;{{PAGENAME}}&#124; &#124;empty&#125;}</code>
+
| valign="top" | <code>1 {&#123;Ifdef&#124; &#124;empty&#125;}</code>
| 1 {{{{PAGENAME}}| |empty}}
+
| 1 {{Ifdef| |empty}}
 
|-
 
|-
| valign="top" | <code>2 {&#123;{{PAGENAME}}&#124;x&#124;gotcha&#125;}</code>
+
| valign="top" | <code>2 {&#123;Ifdef&#124;x&#124;gotcha&#125;}</code>
| 2 {{{{PAGENAME}}|x|gotcha}}
+
| 2 {{Ifdef|x|gotcha}}
 
|-
 
|-
| valign="top" | <code>3 {&#123;{{PAGENAME}}&#124; {&#123;{1&#124; }&#125;} &#124; {&#123;{1&#124; }&#125;} undefined&#125;}</code>
+
| valign="top" | <code>3 {&#123;Ifdef&#124; {&#123;{1&#124; }&#125;} &#124; {&#123;{1&#124; }&#125;} undefined&#125;}</code>
| 3 {{{{PAGENAME}}| {{{1| }}} | {{{1| }}} undefined}}
+
| 3 {{Ifdef| {{{1| }}} | {{{1| }}} undefined}}
 
|-
 
|-
| valign="top" | <code>4 {&#123;{{PAGENAME}}&#124; {&#123;{1&#124;x}&#125;} &#124; {&#123;{1&#124;x}&#125;} for an u&#125;}</code>
+
| valign="top" | <code>4 {&#123;Ifdef&#124; {&#123;{1&#124;x}&#125;} &#124; {&#123;{1&#124;x}&#125;} for an u&#125;}</code>
| 4 {{{{PAGENAME}}| {{{1|x}}} | {{{1|x}}} for an u}}
+
| 4 {{Ifdef| {{{1|x}}} | {{{1|x}}} for an u}}
 
|-
 
|-
| valign="top" | <code>5 {&#123;{{PAGENAME}}&#124; {&#123;{ 1 }&#125;} &#124; {&#123;{1}&#125;} bad idea&#125;}</code>
+
| valign="top" | <code>5 {&#123;Ifdef&#124; {&#123;{ 1 }&#125;} &#124; {&#123;{1}&#125;} bad idea&#125;}</code>
| 5 {{{{PAGENAME}}| {{{ 1 }}} | {{{1}}} bad idea}}
+
| 5 {{Ifdef| {{{ 1 }}} | {{{1}}} bad idea}}
 
|-
 
|-
| valign="top" | <code>6 {&#123;{{PAGENAME}}&#124; {&#123;!&#125;} &#124;see also {&#123;Tlx&#124;Qif&#125;} &#125;}</code>
+
| valign="top" | <code>6 {&#123;Ifdef&#124; {&#123;!&#125;} &#124;see also {&#123;Tl&#124;Qif&#125;} &#125;}</code>
| 6 {{{{PAGENAME}}| {{!}} |see also {{Tl|Qif}} }}
+
| 6 {{Ifdef| {{!}} |see also {{Tl|Qif}} }}
 
|-
 
|-
| valign="top" | <code>7 {&#123;{{PAGENAME}}&#124; okay &#124; 2=see=[&#91;#Caveats&#93;] &#125;}</code>
+
| valign="top" | <code>7 {&#123;Ifdef&#124; okay &#124; 2=see=[&#91;#Caveats&#93;] &#125;}</code>
| 7 {{{{PAGENAME}}| okay | 2=see=[[#Caveats]]}}
+
| 7 {{Ifdef| okay | 2=see=[[#Caveats]]}}
 
|-
 
|-
| valign="top" | <code>8 {&#123;{{PAGENAME}}&#124; oops &#124; see=[&#91;#Caveats&#93;] &#125;}</code>
+
| valign="top" | <code>8 {&#123;Ifdef&#124; oops &#124; see=[&#91;#Caveats&#93;] &#125;}</code>
| 8 {{{{PAGENAME}}| oops | see=[[#Caveats]]}}
+
| 8 {{Ifdef| oops | see=[[#Caveats]]}}
 
|}
 
|}
  

Latest revision as of 01:53, 22 October 2008

Documentation

{{ifdef}} is a compact variant of {{Qif}} for simple "if defined then do" statements without else part. It's the opposite of {{ifndef}}.

Usage

{{Ifdef|value|result}} yields result  if value  isn't blank.

This template is used to simplify the following equivalent but somewhat cryptic code variants:

{{{1{{{1|}}}|{{{2}}}}}}
{{{value{{{value|}}}|{{{result}}}}}}
{{{test{{{test|}}}|{{{then}}}}}}


Example

Code Result
1 {{Ifdef| |empty}} 1
2 {{Ifdef|x|gotcha}} 2 gotcha
3 {{Ifdef| {{{1| }}} | {{{1| }}} undefined}} 3
4 {{Ifdef| {{{1|x}}} | {{{1|x}}} for an u}} 4 x for an u
5 {{Ifdef| {{{ 1 }}} | {{{1}}} bad idea}} 5 {{{1}}} bad idea
6 {{Ifdef| {{!}} |see also {{Tl|Qif}} }} 6 see also {{Qif}}
7 {{Ifdef| okay | 2=see=[[#Caveats]] }} 7 see=#Caveats
8 {{Ifdef| oops | see=[[#Caveats]] }} 8 {{{2}}}

See also a simpler example using ifdef. There's no default in ifdef for the second parameter, because this could hide problematic code.

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}} resulting in "ok=yes" instead of {{ifdef}} resulting in "{{{2}}}".

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

See also

Source

Copied from the page on meta where it is released under the GFDL.