Difference between revisions of "Template:Ifdef/doc"
DESiegel60 (talk | contribs) |
DESiegel60 (talk | contribs) |
||
Line 1: | Line 1: | ||
==Documentation== | ==Documentation== | ||
− | <code>{{[[Template: | + | <code>{{[[Template:Ifdef|{{lcfirst:Ifdef}}]]}}</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>{{ | + | <code>{{Ifdef|value|result}}</code> |
yields ''result''  if ''value''  isn't blank. | yields ''result''  if ''value''  isn't blank. | ||
Line 26: | Line 26: | ||
| '''Result''' | | '''Result''' | ||
|- | |- | ||
− | | valign="top" | <code>1 {{ | + | | valign="top" | <code>1 {{Ifdef| |empty}}</code> |
− | | 1 {{ | + | | 1 {{Ifdef| |empty}} |
|- | |- | ||
− | | valign="top" | <code>2 {{ | + | | valign="top" | <code>2 {{Ifdef|x|gotcha}}</code> |
− | | 2 {{ | + | | 2 {{Ifdef|x|gotcha}} |
|- | |- | ||
− | | valign="top" | <code>3 {{ | + | | valign="top" | <code>3 {{Ifdef| {{{1| }}} | {{{1| }}} undefined}}</code> |
− | | 3 {{ | + | | 3 {{Ifdef| {{{1| }}} | {{{1| }}} undefined}} |
|- | |- | ||
− | | valign="top" | <code>4 {{ | + | | valign="top" | <code>4 {{Ifdef| {{{1|x}}} | {{{1|x}}} for an u}}</code> |
− | | 4 {{ | + | | 4 {{Ifdef| {{{1|x}}} | {{{1|x}}} for an u}} |
|- | |- | ||
− | | valign="top" | <code>5 {{ | + | | valign="top" | <code>5 {{Ifdef| {{{ 1 }}} | {{{1}}} bad idea}}</code> |
− | | 5 {{ | + | | 5 {{Ifdef| {{{ 1 }}} | {{{1}}} bad idea}} |
|- | |- | ||
− | | valign="top" | <code>6 {{ | + | | valign="top" | <code>6 {{Ifdef| {{!}} |see also {{Tl|Qif}} }}</code> |
− | | 6 {{ | + | | 6 {{Ifdef| {{!}} |see also {{Tl|Qif}} }} |
|- | |- | ||
− | | valign="top" | <code>7 {{ | + | | valign="top" | <code>7 {{Ifdef| okay | 2=see=[[#Caveats]] }}</code> |
− | | 7 {{ | + | | 7 {{Ifdef| okay | 2=see=[[#Caveats]]}} |
|- | |- | ||
− | | valign="top" | <code>8 {{ | + | | valign="top" | <code>8 {{Ifdef| oops | see=[[#Caveats]] }}</code> |
− | | 8 {{ | + | | 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 "=" (=) 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
{{ifdef}}
resulting in "ok=yes" instead of{{ifdef}}
resulting in "{{{2}}}".
Substitution works only for {{ifdef}}
, but not for {{ifndef}}
or {{qif}}
.
See also
{{Ifdef}}
{{Ifndef}}
{{Qif}}
- Parser functions #expr:, #if:, #ifeq:, etc.
Source
Copied from the page on meta where it is released under the GFDL.