Template:Both

From Angelina Jordan Wiki
(Redirected from Template:AND)

Documentation

This template, which is intended to be used inside of other templates, returns a true value (specifically, a "1") if both of two inputs exist and contain non-whitespace characters; otherwise it returns an empty string, which is interpreted as a false value. Hence, when used inside of a {{#if:}} parser-function call, it serves as a logical AND operation.

Although the same thing can be accomplished using two nested {{#if:}} calls (which is how this is implemented), using this template in simple situations is quicker and (perhaps) less error-prone. Of course, if you need the additional "logic" provided by the multiple-if approach — i.e., if you need to do one thing if both inputs exist, something different if the first exists but not the second, etc. — then use that approach instead.

Note that if you need a logical OR operation, that is easy enough to accomplish using a single {{#if:}} call. See the note below.

Usage

  • {{both|first|second}}
  • {{both|1=|2=}}

Examples

  • {{both}}
  • {{both|A}}
  • {{both||B}}
  • {{both|A|B}} ⇒ 1

Here's a more realistic example. Assuming that the page "Template:Ex" contains the code:

{{#if: {{both|{{{A|}}}|{{{B|}}}}} | yea | boo}}

then the following template calls give the results shown.

Template call Result
{{ex|A=here|B=present}} yea
{{ex|B=alone}} boo
{{ex|A=|B=non-empty}} boo
{{ex}} boo

Note

There is no equivalent to this template for checking whether either of two parameters is defined (i.e., an OR operation), because that can be accomplished by simply "chaining" the parameters together, like this:

{{#if: {{{A|}}}{{{B|}}} | yea | boo}}

If "Template:Ex" contained this code, then the four results in the table above would be, respectively, "yea", "yea", "yea", and "boo".

Aliases

  • {{AND}}

See also