firstof filter (return the first true value of a list) #42

Closed
wants to merge 2 commits into
from
Commits on Jul 1, 2011
  1. @Alexis-D

    Add a firstof filter.

    Alexis-D committed Jul 1, 2011
    The firstof filter return the first element that is evaluated to True in
    a sequence, it return '' if all elements are evaluated to False.
    
    How to use ?
    ============
    
    {{ ['hello', baz]|firstof }} -> 'hello'
    {{ [0, False]|firstof }} -> ''
    {{ [0, False, foo]|firstof }} with foo='bar' -> 'bar'
    
    It's inspired by django firstof:
    https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#firstof
  2. @Alexis-D