Template Engines

Template Engines

Treinamento no Terra sobre template engines e Nunjucks.

572696200604e59baa59ee90d61f7d02?s=128

Jaydson Gomes

April 01, 2015
Tweet

Transcript

  1. 2.

    “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
  2. 6.

    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)
  3. 7.
  4. 8.

    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
  5. 9.
  6. 11.

    Filters {{ foo | title }} {{ foo | join(",")

    }} {{ foo | replace("foo", "bar") | capitalize }}
  7. 15.
  8. 16.
  9. 18.

    if {% if hungry %} I am hungry {% elif

    tired %} I am tired {% else %} I am good! {% endif %}
  10. 19.

    for

  11. 20.

    for

  12. 21.
  13. 22.

    API

  14. 23.

    API