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

twig.js: The Templating Engine for the Client-Side

twig.js: The Templating Engine for the Client-Side

In this session, we will take an introductory look at twig.js, the Javascript port of the amazing Twig templating engine. We will learn how you can leverage all the power of Twig on the client-side including advanced features such as i18n support, inheritance, or macros. While twig.js can be used standalone, it also has first-class integration with Assetic. Therefore, we will also take a look at one of Assetic's latest features, asset variables, and how we can leverage it with twig.js.

schmittjoh

June 09, 2012
Tweet

More Decks by schmittjoh

Other Decks in Technology

Transcript

  1. 2 Johannes Schmitt | twig.js: The Templating Engine for the

    Client-Side | 06.06.2012 Agenda Why twig.js? How twig.js works Assetic Variables Use Cases
  2. 3 Johannes Schmitt | twig.js: The Templating Engine for the

    Client-Side | 06.06.2012 Why twig.js? Aren‘t there already enough templating engines in Javascript like for example: - Underscore - John Resig‘s Micro-Templating - Mustache.js - Pure - jQote - embeddedJS - tryHandleBarsJs - dust.js - Trimpath - JAML - jSmart - TempoJS - jsViews - Yajet - Kite - BabaJS - vkTemplate - Beard - JsRender - json2html The short answer is no. The longer, it depends.
  3. 4 Johannes Schmitt | twig.js: The Templating Engine for the

    Client-Side | 06.06.2012 twig.js offers some key benefits over existing solutions twig.js is: - fast - secure - flexible - concise - extensible twig.js offers key benefits over other templating engines: - exact same syntax like Twig - same templates for server and client-side (!) twig.js is not: A pure Javascript implementation
  4. 5 Johannes Schmitt | twig.js: The Templating Engine for the

    Client-Side | 06.06.2012 twig.js internally uses Twig for parsing templates Twig parses .twig files twig.js writes AST as Javascript code Abstract Syntax Tree (AST) twig.js behaves as close as possible to Twig, but PHP is required for parsing, and compiling Javascript code.
  5. 6 Johannes Schmitt | twig.js: The Templating Engine for the

    Client-Side | 06.06.2012 Agenda Why twig.js? How twig.js works Assetic Variables Use Cases
  6. 7 Johannes Schmitt | twig.js: The Templating Engine for the

    Client-Side | 06.06.2012 In twig.js, there is a distinct difference between compilation and runtime Compilation Time Runtime Functions Filters Tests Compilation Time should generally be preferred when possible.
  7. 8 Johannes Schmitt | twig.js: The Templating Engine for the

    Client-Side | 06.06.2012 twig.js has almost the same architecture like Twig JSCompiler FilterCompiler TypeCompiler TestCompiler Function Map Filter Map
  8. 9 Johannes Schmitt | twig.js: The Templating Engine for the

    Client-Side | 06.06.2012 twig.js has almost the same architecture like Twig twig.Environment Filters Functions Tests Globals Extensions
  9. 10 Johannes Schmitt | twig.js: The Templating Engine for the

    Client-Side | 06.06.2012 Agenda Why twig.js? How twig.js works Assetic Variables Use Cases
  10. 11 Johannes Schmitt | twig.js: The Templating Engine for the

    Client-Side | 06.06.2012 twig.js allows you to easily internationalize your Javascript Twig Template Assetic English Version German Version French Version
  11. 12 Johannes Schmitt | twig.js: The Templating Engine for the

    Client-Side | 06.06.2012 twig.js is integrated into Assetic AsseticFilter Compile Request CompilerRequestHandler JSCompiler
  12. 13 Johannes Schmitt | twig.js: The Templating Engine for the

    Client-Side | 06.06.2012 Why twig.js? How twig.js works Assetic Variables Use Cases Agenda
  13. 14 Johannes Schmitt | twig.js: The Templating Engine for the

    Client-Side | 06.06.2012 Use Case #1: Client-Side Application
  14. 15 Johannes Schmitt | twig.js: The Templating Engine for the

    Client-Side | 06.06.2012 Use Case #2: Rendering Small Pieces on the Client-Side
  15. 16 Johannes Schmitt | twig.js: The Templating Engine for the

    Client-Side | 06.06.2012 Use Case #3: Mixed Client-Side and Server-Side Rendering
  16. 17 Johannes Schmitt | twig.js: The Templating Engine for the

    Client-Side | 06.06.2012 Thanks! Twitter: @JohannesMS Github: schmittjoh http://jmsyst.com/