kblomqvist / yasha

A command-line tool to render Jinja templates for great good
MIT License
243 stars 23 forks source link

How to set a default value if environment variable is not set? #36

Closed mastermindg closed 6 years ago

mastermindg commented 6 years ago

I'm currently using if...else.. statements to wrap my code but it would be easier if I could just set defaults instead. Is there any way to set a default value if an environment variable is not set?

minutes: {{ 5 | 'INTERVAL' | env }}

When I try this I get an error:

File "config/base.j2", line 9, in template
    minutes: {{ 5 | 'INTERVAL' | env }}
jinja2.exceptions.TemplateSyntaxError: expected token 'name', got 'string'
kblomqvist commented 6 years ago
minutes: {{ 'INTERVAL' | env(default=5) }}