Pergi ke kandungan


Daripada Wikipedia, ensiklopedia bebas.

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[sunting sumber]

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


  • {{#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 Templat:Cnw or Templat: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[sunting sumber]

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 a

{{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 a

Internal technical details[sunting sumber]

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[sunting sumber]

#if:[sunting sumber]

Condition: string not empty.

See also[sunting sumber]