Reputation: 39018
I'm using Mako templates in a Python project.
The value None sometimes comes through for a contact title. I want to hide None if the value is None
.
Current code:
<td class="data-career request-row">
%if 'title' in message['contact'] and 'title' is not 'None':
${message['contact']['title']}
%endif
</td>
I also tried:
%if 'title' in message['contact'] and 'title' is not None:
However None still shows up, so I'm curious as to what the correct way to check for an incoming string value is in Mako?
I couldn't find anything on their docs site.
Upvotes: 1
Views: 1488
Reputation: 56467
Obviously string 'title'
cannot be None
because it is... well, 'title'
. :D
%if 'title' in message['contact'] and message['contact']['title'] is not None:
${message['contact']['title']}
%endif
or
%if 'title' in message['contact']:
${message['contact']['title'] or ''}
%endif
or simpliest/shortest
${message['contact'].get('title', None) or ''}
Upvotes: 2