Slide 1

Slide 1 text

Template Engines Nunjucks & Jinja

Slide 2

Slide 2 text

“Template engines are tools to separate program- logic and presentation into two independent parts. This makes the development of both logic and presentation easier, improves flexibility and eases modification and maintenance.” http://www.simple-is-better.org/template

Slide 3

Slide 3 text

String interpolation

Slide 4

Slide 4 text

String interpolation

Slide 5

Slide 5 text

String interpolation

Slide 6

Slide 6 text

Template logic ● placeholders (for string-substitution) ● if-defined-conditionals (to test presence/absence of some data) ● foreach-data-loops (for multi-valued data/lists) ● recursive macros (to walk recursive data-structures)

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

Nunjucks ● Rich: Powerful language with block inheritance, auto escaping, macros, async control ● Fast & Lean: High-performant ● Small: 8K gzipped runtime with precompiled templates in the browser ● Extensible: Crazy extensible with custom filters and extensions ● Everywhere: Available in node and all modern web browsers

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

Variables {{ username }} {{ foo.bar }} {{ foo["bar"] }}

Slide 11

Slide 11 text

Filters {{ foo | title }} {{ foo | join(",") }} {{ foo | replace("foo", "bar") | capitalize }}

Slide 12

Slide 12 text

Template Inheritance

Slide 13

Slide 13 text

parent.html

Slide 14

Slide 14 text

my_template.html

Slide 15

Slide 15 text

OUTPUT

Slide 16

Slide 16 text

Tags

Slide 17

Slide 17 text

if {% if variable %} It is true {% endif %}

Slide 18

Slide 18 text

if {% if hungry %} I am hungry {% elif tired %} I am tired {% else %} I am good! {% endif %}

Slide 19

Slide 19 text

for

Slide 20

Slide 20 text

for

Slide 21

Slide 21 text

macros

Slide 22

Slide 22 text

API

Slide 23

Slide 23 text

API

Slide 24

Slide 24 text

Sample http://github.tpn.terra.com/jaydson-gomes/zaz-app-card http://dsv-fe01-mia.dev.terra.com/~jaydson.gomes/zaz- app-card/dist/samples/pt.html