Skip to content

Conformance Examples 0.1.0 — Transforms: transform-default

default-null-input-uses-default

A null (missing) input triggers the fallback.

Template

{{ missing | default: "fallback" }}

Context

{}

Output

fallback

default-explicit-null-uses-default

An explicit null value triggers the fallback.

Template

{{ x | default: "fallback" }}

Context

{
    "x": null
}

Output

fallback

default-empty-string-uses-default

An empty string input triggers the fallback.

Template

{{ x | default: "fallback" }}

Context

{
    "x": ""
}

Output

fallback

default-empty-list-uses-default

An empty list input triggers the fallback.

Template

{{ xs | default: "fallback" }}

Context

{
    "xs": []
}

Output

fallback

default-non-empty-string-passes-through

A non-empty string is returned unchanged.

Template

{{ x | default: "fallback" }}

Context

{
    "x": "hello"
}

Output

hello

default-non-empty-list-passes-through

A non-empty list is returned unchanged.

Template

{{ xs | default: "fallback" }}

Context

{
    "xs": [
        1,
        2,
        3
    ]
}

Output

[1,2,3]

default-false-passes-through

A false boolean passes through unchanged (allow_false is always true).

Template

{{ x | default: "fallback" }}

Context

{
    "x": false
}

Output

false

default-zero-passes-through

Zero passes through unchanged.

Template

{{ x | default: "fallback" }}

Context

{
    "x": 0
}

Output

0

Source fixture: transforms/transform-default.json