Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Template Engines

Template Engines

Treinamento no Terra sobre template engines e Nunjucks.

Jaydson Gomes

April 01, 2015
Tweet

More Decks by Jaydson Gomes

Other Decks in Programming

Transcript

  1. “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. 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. 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
  4. Filters {{ foo | title }} {{ foo | join(",")

    }} {{ foo | replace("foo", "bar") | capitalize }}
  5. if {% if hungry %} I am hungry {% elif

    tired %} I am tired {% else %} I am good! {% endif %}
  6. for

  7. for

  8. API

  9. API