Skip to content

Conformance Examples 0.1.0 — Render: logical-operators

or-true-true

Both operands truthy: or evaluates to true.

Template

{{ a or b }}

Context

{
    "a": true,
    "b": true
}

Output

true

or-true-false

One truthy operand suffices: or evaluates to true.

Template

{{ a or b }}

Context

{
    "a": true,
    "b": false
}

Output

true

or-false-true

One truthy operand suffices regardless of position: or evaluates to true.

Template

{{ a or b }}

Context

{
    "a": false,
    "b": true
}

Output

true

or-false-false

Both operands falsy: or evaluates to false.

Template

{{ a or b }}

Context

{
    "a": false,
    "b": false
}

Output

false

or-uppercase

OR in all-caps is recognised identically to lowercase.

Template

{{ a OR b }}

Context

{
    "a": true,
    "b": false
}

Output

true

or-mixed-case

Or with mixed case is recognised identically to lowercase.

Template

{{ a Or b }}

Context

{
    "a": false,
    "b": false
}

Output

false

and-true-true

Both operands truthy: and evaluates to true.

Template

{{ a and b }}

Context

{
    "a": true,
    "b": true
}

Output

true

and-true-false

One falsy operand: and evaluates to false.

Template

{{ a and b }}

Context

{
    "a": true,
    "b": false
}

Output

false

and-empty-string-and-nonempty

Empty string is falsy under kBars truthiness; and short-circuits to false.

Template

{{ a and b }}

Context

{
    "a": "",
    "b": "x"
}

Output

false

and-empty-array-and-object

Empty array is falsy and any object is truthy: and evaluates to false.

Template

{{ a and b }}

Context

{
    "a": [],
    "b": {}
}

Output

false

or-missing-and-literal

Missing identifier resolves to null (falsy); a non-empty string literal is truthy; or evaluates to true.

Template

{{ missing or "x" }}

Context

{}

Output

true

or-zero-and-zero-point-zero

Numeric literal 0 and 0.0 are both falsy under truthiness: or evaluates to false.

Template

{{ 0 or 0.0 }}

Context

{}

Output

false

or-zero-and-one

0 is falsy, 1 is truthy: or evaluates to true.

Template

{{ 0 or 1 }}

Context

{}

Output

true

and-in-if-block

Logical operators flow naturally through #if expression slots.

Template

{{#if a and b }}yes{{else}}no{{/if}}

Context

{
    "a": true,
    "b": true
}

Output

yes

or-in-unless-block

Logical operators flow through #unless expression slots; both operands falsy means the body renders.

Template

{{#unless a or b }}neither{{/unless}}

Context

{
    "a": false,
    "b": false
}

Output

neither

or-triple-mustache

Triple-mustache renders the binary result (a boolean) verbatim; the HTML-looking literal '' does not appear in the output because the operator returned the boolean true.

Template

{{{ a or "<b>" }}}

Context

{
    "a": false
}

Output

true

Source fixture: render/logical-operators.json