Jump to content

Template:Iszero/doc

From Wikibooks, open books for an open world

{{iszero}} returns the passed value if it evaluates as non-zero. If it is zero, by default the template returns nothing, or it can return any other value you specify. Blank inputs are treated as zeros by default, but that can be overridden.

Tip:

Non-numeric text generally will evaluate as non-zero, so you may want to pass the input value through {{isnumeric}} first (see examples 12 and 14) and treat non-numeric text as a blank.


Recognizes the following parameters

  1. The value to check; required
  2. blank= — To have blank values not be treated as zero, set this to any non-zero value you want returned; optional
  3. whenzero= — Set to the value you want returned if the input value evaluates to zero; optional (defaults to blank)
  4. whenblank= — Set to the value you want returned if the input value is blank; optional (defaults to blank)

Examples

[edit source]
  1. {{iszero}} → Blank
  2. {{iszero|0}} → Zero
  3. {{iszero|3}} → Default
  4. {{iszero|0|whenzero=Zero|whenblank=Blank}} → Zero
  5. {{iszero|whenzero=Zero|whenblank=Blank}} → Blank
  6. {{iszero||whenzero=Zero|whenblank=Blank}} → Blank
  7. {{iszero|blank=1|whenzero=Zero|whenblank=Blank}} → Blank
  8. {{iszero||blank=1|whenzero=Zero|whenblank=Blank}} → Blank
  9. {{iszero|0|blank=1|whenzero=Zero|whenblank=Blank}} → Zero
  10. {{iszero|3|blank=1|whenzero=Zero|whenblank=Blank}} → Default
  11. {{iszero|Some text|blank=1|whenzero=Zero|whenblank=Blank}} → Default
  12. {{iszero|{{isnumeric|Some text}}|blank=1|whenzero=Zero|whenblank=Blank}} → Blank
  13. {{iszero|Some text|blank=0|whenzero=Zero|whenblank=Blank}} → Default
  14. {{iszero|{{isnumeric|Some text}}|blank=0|whenzero=Zero|whenblank=Blank}} → Blank