Toggle search
Search
Toggle menu
notifications
Toggle personal menu
Editing
Template:Ifnotempty/doc
Template page
Views
Read
Edit source
View history
associated-pages
Template
Discussion
More actions
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Documentation subpage}}{{high-use}} With this template [[mw:Help:Extension:ParserFunctions|#if]] can be used in a way such that it does not [[m:Help:Newlines_and_spaces#Stripping_on_expansion|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== *<code><nowiki>{{ifnotempty| x | A | B }}</nowiki></code> gives "{{ifnotempty| x | A | B }}" *<code><nowiki>{{ifnotempty|x| A | B }}</nowiki></code> gives "{{ifnotempty|x| A | B }}" *<code><nowiki>{{ifnotempty| | A | B }}</nowiki></code> gives "{{ifnotempty| | A | B }}" *<code><nowiki>{{ifnotempty|| A | B }}</nowiki></code> gives "{{ifnotempty|| A | B }}" Compare: *<code><nowiki>{{#if:x| A | B }}</nowiki></code> gives "{{#if:x| A | B }}" *<code><nowiki>{{#if:| A | B }}</nowiki></code> gives "{{#if:| A | 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 <syntaxhighlight lang="wikitext"> {{ {{#if: {{{1}}} | P1 | P2 }} |{{{2}}}|{{{3}}}}} </syntaxhighlight> ==See also== *[[Template:If]] *[[m:Template:Ifnotempty]] <includeonly>{{sandbox other|| <!-- Categories below this line --> [[Category:If-then-else templates]] }}</includeonly>
Summary:
Please note that all contributions to Turing Complete are considered to be released under the Creative Commons Attribution-ShareAlike (see
TuringComplete:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Documentation subpage
(
edit
)
Template:High-use
(
view source
)
Template:Ifnotempty
(
edit
)
Template:Mbox
(
edit
)
Template:P1
(
edit
)
Template:P2
(
edit
)