Skabelon:Ifnotempty: Forskelle mellem versioner

Fra Skrivekunst.dk
(Oprettede siden med "<includeonly>{{{{{|safesubst:}}}{{{{{|safesubst:}}}#if:{{{1}}}|p1|p2}}|{{{2}}}|{{{3|}}}}}</includeonly><noinclude><div class="template-documentation" style="margin-top:1em;"...")
 
No edit summary
 
(En mellemliggende version af den samme bruger vises ikke)
Linje 1: Linje 1:
<includeonly>{{{{{|safesubst:}}}{{{{{|safesubst:}}}#if:{{{1}}}|p1|p2}}|{{{2}}}|{{{3|}}}}}</includeonly><noinclude><div class="template-documentation" style="margin-top:1em;">{{#if:defaultnotblank|<div style="padding-bottom:3px; border-bottom:1px solid #aaa; margin-bottom:1ex;">
<noinclude>__NOINDEX__</noinclude><includeonly>{{{{{|safesubst:}}}{{{{{|safesubst:}}}#if:{{{1}}}|p1|p2}}|{{{2}}}|{{{3|}}}}}</includeonly><noinclude><div class="template-documentation" style="margin-top:1em;">{{#if:defaultnotblank|<div style="padding-bottom:3px; border-bottom:1px solid #aaa; margin-bottom:1ex;">
<span style="font-size:150%">Documentation</span></div>}}
<span style="font-size:150%">Documentation</span></div>}}
With this template [[mw:Help:Extension:ParserFunctions|#if]] can be used in a way such that it does not [[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.
With this template [[mw:Help:Extension:ParserFunctions|#if]] can be used in a way such that it does not [[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.


==Usage==
==Usage==
*<code><nowiki>{{ifnotempty|x| p | q }}</nowiki></code> gives "{{ifnotempty|x| p | q }}"
*<code><nowiki>{{Ifnotempty|x| p | q }}</nowiki></code> gives "{{Ifnotempty|x| p | q }}"
*<code><nowiki>{{ifnotempty|| p | q }}</nowiki></code> gives "{{ifnotempty|| p | q }}"
*<code><nowiki>{{Ifnotempty|| p | q }}</nowiki></code> gives "{{Ifnotempty|| p | q }}"
Compare:
Compare:
*<code><nowiki>{{#if:x| p | q }}</nowiki></code> gives "{{#if:x| p | q }}"
*<code><nowiki>{{#if:x| p | q }}</nowiki></code> gives "{{#if:x| p | q }}"

Nuværende version fra 31. jul. 2021, 18:20

Documentation

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.

Usage

  • {{Ifnotempty|x| p | q }} gives " p "
  • {{Ifnotempty|| p | q }} gives " q "

Compare:

  • {{#if:x| p | q }} gives "p"

Note that, unlike parser functions, templates require writing equals signs in values of unnamed parameters as {{=}}

For full substitution, simply use Skabelon:cnw or Skabelon:cnw. If the condition contains a parser function, template, or variable, that should be substituted too. Optionally the "then" or "else" part can also be substituted.

Expansion depth limit

13 levels allowed:

{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|a}}}}}}}}}}}}}}}}}}}}}}}}}} gives Skabelon:ifnotempty

{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|a}}}}}}}}}}}}}}}}}}}}}}}}}}}} gives Skabelon:ifnotempty

Internal technical details

For evaluating the condition the template uses the actual parser function; however, not directly with p and q, because this strips spaces and newlines from the result, but with index values 1 and 2. The result can be 1, 2. The template with the applicable name is called (Template:P1 or Template:P2), with as parameters p and q.

Conditions

#if:

Condition: string not empty.

Skrivekunst.dk bruger cookies for at forbedre brugeroplevelsen. Tryk OK for at fjerne denne besked.