• Home
  • Random
  • Nearby
  • Log in
  • Settings
Donate Now If Wikipedia is useful to you, please give today.
  • About Wikipedia
  • Disclaimers
Wikipedia

Template:Ifnotempty

  • Template
  • Talk
  • Language
  • Watch
  • View source
Template documentation[view] [edit] [history] [purge]
WarningThis template is used on approximately 17,000 pages and changes may be widely noticed. Test changes in the template's /sandbox or /testcases subpages, or in your own user subpage. Consider discussing changes on the talk page before implementing them.

With this template #if can be used in a way such that it does not strip spaces and newlines from the "then" and "else" part. For evaluating the condition spaces and newlines are stripped like with ParserFunctions.

This template can be substituted.

Usage

  • {{ifnotempty| x | A | B }} gives " A "
  • {{ifnotempty|x| A | B }} gives " A "
  • {{ifnotempty| | A | B }} gives " B "
  • {{ifnotempty|| A | B }} gives " B "

Compare:

  • {{#if:x| A | B }} gives "A"
  • {{#if:| A | B }} gives "B"

Internal technical details

For evaluating the condition (determining non-emptiness of the first parameter) the template uses parser function #if, producing 1 if the condition is true, and 2 otherwise. The template with name equal to "P" followed by the index value produced (hence Template:P1 or Template:P2), is called with as parameters A and B. This produces either A or B, without trimming. The template's code is a substitution-safe version of

{{ {{#if: {{{1}}} | P1 | P2 }} |{{{2}}}|{{{3}}}}}

See also

  • Template:If
  • m:Template:Ifnotempty
The above documentation is transcluded from Template:Ifnotempty/doc. (edit | history)
Editors can experiment in this template's sandbox (create | mirror) and testcases (create) pages.
Add categories to the /doc subpage. Subpages of this template.
Retrieved from "https://en.wikipedia.org/w/index.php?title=Template:Ifnotempty&oldid=1304298682"
Last edited on 5 August 2025, at 05:19

Languages

    • العربية
    • Авар
    • Azərbaycanca
    • تۆرکجه
    • বাংলা
    • 閩南語 / Bân-lâm-gí
    • Беларуская (тарашкевіца)
    • Bikol Central
    • Bosanski
    • Dansk
    • Ελληνικά
    • Эрзянь
    • فارسی
    • Føroyskt
    • ગુજરાતી
    • 한국어
    • Bahasa Indonesia
    • Latina
    • മലയാളം
    • Bahasa Melayu
    • Мокшень
    • ਪੰਜਾਬੀ
    • Português
    • Русский
    • Scots
    • Simple English
    • தமிழ்
    • ไทย
    • Tiếng Việt
    • 中文
    • Kadazandusun
    Wikipedia
    • Wikimedia Foundation
    • Powered by MediaWiki
    • This page was last edited on 5 August 2025, at 05:19 (UTC).
    • Content is available under CC BY-SA 4.0 unless otherwise noted.
    • Privacy policy
    • About Wikipedia
    • Disclaimers
    • Contact Wikipedia
    • Code of Conduct
    • Developers
    • Statistics
    • Cookie statement
    • Terms of Use
    • Desktop