Difference between revisions of "Template:Ifndef/doc"

From ISFDB
Jump to navigation Jump to search
(New page: <code>{{[[Template:{{PAGENAME}}|{{lcfirst:{{PAGENAME}}}}]]}}</code> is a compact variant of {{Tl|Qif}} for simple "'''if''' ''defined'' '''then void else''' ''do''" statements w...)
 
Line 25: Line 25:
 
| '''Result'''
 
| '''Result'''
 
|-
 
|-
| valign="top" | <code>1 {&#123;{{PAGENAME}}&#124; &#124;empty&#125;}</code>
+
| valign="top" | <code>1 {&#123;Ifndef&#124; &#124;empty&#125;}</code>
| 1 {{{{PAGENAME}}| |empty}}
+
| 1 {{Ifndef| |empty}}
 
|-
 
|-
| valign="top" | <code>2 {&#123;{{PAGENAME}}&#124;x&#124;gotcha&#125;}</code>
+
| valign="top" | <code>2 {&#123;Ifndef&#124;x&#124;gotcha&#125;}</code>
| 2 {{{{PAGENAME}}|x|gotcha}}
+
| 2 {{Ifndef|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;Ifndef&#124; {&#123;{1&#124; }&#125;} &#124; {&#123;{1&#124; }&#125;} undefined&#125;}</code>
| 3 {{{{PAGENAME}}| {{{1| }}} | {{{1| }}} undefined}}
+
| 3 {{Ifndef| {{{1| }}} | {{{1| }}} undefined}}
 
|-
 
|-
| valign="top" | <code>4 {&#123;{{PAGENAME}}&#124; {&#123;{1 &#160;}&#125;} &#124; {&#123;{1 &#160;}&#125;} bad idea&#125;}</code>
+
| valign="top" | <code>4 {&#123;Ifndef&#124; {&#123;{1 &#160;}&#125;} &#124; {&#123;{1 &#160;}&#125;} bad idea&#125;}</code>
| 4 {{{{PAGENAME}}| {{{1  }}} | {{{1  }}} bad idea}}
+
| 4 {{Ifndef| {{{1  }}} | {{{1  }}} bad idea}}
 
|-
 
|-
| valign="top" | <code>5 {&#123;{{PAGENAME}}&#124; {&#123;ns:0&#125;} &#124; main namespace&#125;}</code>
+
| valign="top" | <code>5 {&#123;Ifndef&#124; {&#123;ns:0&#125;} &#124; main namespace&#125;}</code>
| 5 {{{{PAGENAME}}| {{ns:0}} | main namespace}}
+
| 5 {{Ifndef| {{ns:0}} | main namespace}}
 
|-
 
|-
| valign="top" | <code>6 {&#123;{{PAGENAME}}&#124;&#124;compare {&#123;Tlx&#124;ifdef&#125;} &#125;}</code>
+
| valign="top" | <code>6 {&#123;Ifndef&#124;&#124;compare {&#123;Tl&#124;ifdef&#125;} &#125;}</code>
| 6 {{{{PAGENAME}}||compare {{Tl|ifdef}} }}
+
| 6 {{Ifndef||compare {{Tl|ifdef}} }}
 
|-
 
|-
| valign="top" | <code>7 {&#123;{{PAGENAME}}&#124;&#124; 2=see=[&#91;#Caveats&#93;] &#125;}</code>
+
| valign="top" | <code>7 {&#123;Ifndef&#124;&#124; 2=see=[&#91;#Caveats&#93;] &#125;}</code>
| 7 {{{{PAGENAME}}|| 2=see=[[#Caveats]]}}
+
| 7 {{Ifndef|| 2=see=[[#Caveats]]}}
 
|-
 
|-
| valign="top" | <code>8 {&#123;{{PAGENAME}}&#124;&#124; see=[&#91;#Caveats&#93;] &#125;}</code>
+
| valign="top" | <code>8 {&#123;Ifndef&#124;&#124; see=[&#91;#Caveats&#93;] &#125;}</code>
| 8 {{{{PAGENAME}}|| see=[[#Caveats]]}}
+
| 8 {{Ifndef|| see=[[#Caveats]]}}
 
|}
 
|}
  
 
''Unlike '''ifdef''' the minimalistic '''ifndef''' cannot reject a missing second parameter.''
 
''Unlike '''ifdef''' the minimalistic '''ifndef''' cannot reject a missing second parameter.''
 +
 +
  
 
=== Caveats ===
 
=== Caveats ===

Revision as of 01:37, 22 October 2008

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

Usage

{{Ifndef/doc|value|result}} yields result  if value  is blank.

This simple template cannot be substituted, it's used to simplify the following equivalent but somewhat cryptic (names don't matter) code variants:

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


Example

Code Result
1 {{Ifndef| |empty}} 1 empty
2 {{Ifndef|x|gotcha}} 2
3 {{Ifndef| {{{1| }}} | {{{1| }}} undefined}} 3 undefined
4 {{Ifndef| {{{1  }}} | {{{1  }}} bad idea}} 4
5 {{Ifndef| {{ns:0}} | main namespace}} 5 main namespace
6 {{Ifndef||compare {{Tl|ifdef}} }} 6 compare {{ifdef}}
7 {{Ifndef|| 2=see=[[#Caveats]] }} 7 see=#Caveats
8 {{Ifndef|| see=[[#Caveats]] }} 8

Unlike ifdef the minimalistic ifndef cannot reject a missing second parameter.


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

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