Template:Ifndef

From ISFDB

Jump to: navigation, search

{{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}}.

Contents

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|}}}|}}}


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:

  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}}.

Source

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

Personal tools