I have an output as follows:
[{
'stderr': 'error: cannot open file',
},
{
'stderr': '',
}]
Jinja snipper:
{{ php_command_result.results | map(attribute='stderr') | sort | join('\r - ') }}"
Returns a trailing -
at the end because stderr
is empty. How can I ignore empty values?
Jinja2 being a templating language has no need for wide choice of loop types so we only get for loop. For loops start with {% for my_item in my_collection %} and end with {% endfor %} . This is very similar to how you'd loop over an iterable in Python.
Did you try rejectattr?
{{ php_command_result.results | rejectattr('stderr', 'equalto', '') | map(attribute='stderr') | sort | join('\r - ') }}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With