Using filter pipelines
Let’s say we want to modify a colour and then insert its hex into the template:
highlight = {{ (red | sub(saturation=60)).hex }}$ whiskers -f mocha my-cool-template.txtError: Template is invalid
Caused by: 0: Failed to parse 'test.tera' 1: --> 1:42 | 1 | highlight = {{ (red | sub(saturation=60)).hex }} | ^--- | = expected `or`, `and`, or a variable end (`}}`)What happened? Well, Tera doesn’t allow inserting parentheses around a filter pipeline like this. Instead, you have to use the get filter:
highlight = {{ (red | sub(saturation=60)).hex }}highlight = {{ red | sub(saturation=60) | get(key="hex") }}$ whiskers -f mocha my-cool-template.txthighlight = cdb1b9This works for getting any property from an object:
highlight_red = {{ red | sub(saturation=60) | get(key="rgb") | get(key="r") }}$ whiskers -f mocha my-cool-template.txthighlight_red = 205This example is equivalent to adding .rgb.r on the end of the object.
Getting the hex string from a colour at the end of a filter pipeline is such a common need that we added a dedicated hex filter for it:
highlight = {{ red | sub(saturation=60) | get(key="hex") }}highlight = {{ red | sub(saturation=60) | hex }}$ whiskers -f mocha my-cool-template.txthighlight = cdb1b9