How can I ignore an item from a list when navigating through Jinja?

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 the final - at the end, because stderr empty. How to ignore empty values?

+5
source share
1 answer

Have you tried rejectattr ?

 {{ php_command_result.results | rejectattr('stderr', 'equalto', '') | map(attribute='stderr') | sort | join('\r - ') }}" 
+7
source

All Articles