Edgewall Software

Changes between Version 4 and Version 5 of TracDev/PortingFromGenshiToJinja


Ignore:
Timestamp:
Feb 22, 2016, 9:39:58 PM (8 years ago)
Author:
Christian Boos
Comment:

a few more examples for setting complex variables

Legend:

Unmodified
Added
Removed
Modified
  • TracDev/PortingFromGenshiToJinja

    v4 v5  
    3636
    3737However, Jinja2 expressions are only //similar// to Python expressions, there are a few differences and limitations, see [http://jinja.pocoo.org/docs/dev/templates/#expressions expressions] doc.
     38
     39See also [#setcomplexvariabels set complex variables] below for more involved examples.
    3840
    3941=== include another template
     
    210212}}}
    211213
     214If you wonder why the `if all(...)` expression morphed into `if not components|...`, it's because Jinja2 expressions are similar to Python expressions, but not quite the same.
     215
     216=== set complex variables
    212217Note that Jinja2 expressions are a subset of Python expressions, and for the sake of simplicity the generator expressions are not part of that subset. This limitation often requires one to make creative use of [http://jinja.pocoo.org/docs/dev/templates/#filters filters], [http://jinja.pocoo.org/docs/dev/templates/#builtin-filters built-in] or custom (`min`, `max`, `trim`, `flatten`).
    213218
     
    217222|| `${', '.join([p.name for p in faulty_plugins])}` || \
    218223|| `${faulty_plugins|map('name')|join(', ')}` ||
     224|| `sum(1 for change in changes if 'cnum' in change)` || \
     225|| `changes|selectattr('cnum')|list|count` ||
     226|| `sum(1 for change in changes if 'cnum' not in change)` || \
     227|| `changes|rejectattr('cnum')|list|count` ||
    219228|| ... || ... ||
    220229