On 14 May 2012 09:26, Malthe Borch <[email protected]> wrote:
> Alternatively, you can use the ternary operator if you strictly want
> to guard against ``None``:
>
> ${variable if variable is not None else 'some default value'}
To keep it readable, I have an utility function available to all templates:
> def coalesce(*seq):
> el = None
> for el in seq:
> if el is not None:
> return el
> return el
then it becomes ${coalesce(variable, 'some default value')}
and sometimes this one:
> def coalesce_wrap(wrapper, *seq):
> el = coalesce(*seq)
> if el is not None:
> return wrapper(el)
> else:
> return None
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en.