How can I ignore an element from a list when loopi

2019-04-29 23:02发布

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?

1条回答
ら.Afraid
2楼-- · 2019-04-29 23:57

Did you try rejectattr?

{{ php_command_result.results | rejectattr('stderr', 'equalto', '') | map(attribute='stderr') | sort | join('\r - ') }}"
查看更多
登录 后发表回答