Template talk:Ifndef
From Meta, a Wikimedia project coordination wiki
Contents |
[edit] Documentation
{{ifndef}} 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}}.
[edit] Usage
{{Ifndef|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|}}}|}}}
[edit] 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 {{Tlx|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.
[edit] 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| |2=ok=yes}} resulting in "ok=yes
" instead of {{ifndef| |bad=idea}} resulting in " ".
Substitution works only for {{ifdef}}, but not for {{ifndef}} or {{qif}}.
[edit] See also
- template:Ifndef ( talk edit history links )
- template:Ifdef ( talk edit history links )
[edit] Discussion
Add issues below as you see fit, sign with ~~~~