default
Default returns the fallback value if the input is nil or an empty string.
Default returns the fallback value if the input is nil or an empty string.
Input
any
Parameters
| # | Type | Required |
|---|---|---|
| 0 | any | yes |
Returns
any
Examples
Fall back to a placeholder name
Input
name = ""Template
{{ name | default:'anonymous' }}Output
anonymousUse a default count when missing
Input
count = nullTemplate
{{ count | default:0 }}Output
0Avoid an error when a lookup misses
Input
items = [{"id": 1, "name": "Mug"}]Template
{{ items | find:'id',99 | default:{} }}Output
{}How is this guide?