Difference between revisions of "Template:Ifndef/doc"
DESiegel60 (talk | contribs) (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...) |
DESiegel60 (talk | contribs) |
||
Line 25: | Line 25: | ||
| '''Result''' | | '''Result''' | ||
|- | |- | ||
− | | valign="top" | <code>1 {{ | + | | valign="top" | <code>1 {{Ifndef| |empty}}</code> |
− | | 1 {{ | + | | 1 {{Ifndef| |empty}} |
|- | |- | ||
− | | valign="top" | <code>2 {{ | + | | valign="top" | <code>2 {{Ifndef|x|gotcha}}</code> |
− | | 2 {{ | + | | 2 {{Ifndef|x|gotcha}} |
|- | |- | ||
− | | valign="top" | <code>3 {{ | + | | valign="top" | <code>3 {{Ifndef| {{{1| }}} | {{{1| }}} undefined}}</code> |
− | | 3 {{ | + | | 3 {{Ifndef| {{{1| }}} | {{{1| }}} undefined}} |
|- | |- | ||
− | | valign="top" | <code>4 {{ | + | | valign="top" | <code>4 {{Ifndef| {{{1  }}} | {{{1  }}} bad idea}}</code> |
− | | 4 {{ | + | | 4 {{Ifndef| {{{1 }}} | {{{1 }}} bad idea}} |
|- | |- | ||
− | | valign="top" | <code>5 {{ | + | | valign="top" | <code>5 {{Ifndef| {{ns:0}} | main namespace}}</code> |
− | | 5 {{ | + | | 5 {{Ifndef| {{ns:0}} | main namespace}} |
|- | |- | ||
− | | valign="top" | <code>6 {{ | + | | valign="top" | <code>6 {{Ifndef||compare {{Tl|ifdef}} }}</code> |
− | | 6 {{ | + | | 6 {{Ifndef||compare {{Tl|ifdef}} }} |
|- | |- | ||
− | | valign="top" | <code>7 {{ | + | | valign="top" | <code>7 {{Ifndef|| 2=see=[[#Caveats]] }}</code> |
− | | 7 {{ | + | | 7 {{Ifndef|| 2=see=[[#Caveats]]}} |
|- | |- | ||
− | | valign="top" | <code>8 {{ | + | | valign="top" | <code>8 {{Ifndef|| see=[[#Caveats]] }}</code> |
− | | 8 {{ | + | | 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 "=" (=) and "|" (|) cannot be used as is in parameters. The numeric character references = and | are often good enough, but for Wiki and XHTML markup the literal characters are required:
- For | template:! (edit•talk•links•history) offers a workaround.
- 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}}
.