The best Drupal news and links delivered to your inbox every week

Using Twig: The New Template Engine In Drupal 8 - Jen Lampton, Fabian Franz, John Albin Wilkins - DrupalCon Portland 2013

Check out the DrupalCon Portland notes hub page for notes from other sessions at DrupalCon Portland.

Session: Using Twig: The New Template Engine In Drupal 8

Day - Time Slot: Wednesday, May 22 - 03:45pm–04:45pm

Presenters:

Jen Lampton
Twitter: jenlampton
Drupal.org: jenlampton

Fabian Franz
Twitter: fabianfranz
Drupal.org: Fabianx

John Albin Wilkins
Twitter: JohnAlbin
Drupal.org: JohnAlbin

Session page

Slides: Not yet available

Video

New Theme Engine TWIG

Why TWIG

  • Already documented
  • Extendable
  • Secure
  • Fast
  • IDE integration
  • Looks like other languages
  • Same creator as symfony
  • Can drill down into all variables with dots .
  • user command with %

Creating a Theme

  • Page template
  • Blog template
  • Multiple image field display section tags

twigified Example Theme

  • Less duplication of code
  • blocking allows you to override an existing template without duplicating code. Only the difference needs to be in the new template.
  • Override templates with multiple values

Improvements/Fixing D7 pain points

  • Dot operators = more standard way to print variables
  • Remove need for the render function
  • Working on all converting templates. Then they will be converting theme functions(refactoring and consolidation)
  • Variables automatically sanitized
  • Less Drupal specific. Makes it easier for people from other projects to create Drupal themes

Drupal 8 Improvements

  • Remove theme functions
  • Remove process functions
  • Remove Drupal render pipeline(Work in progress)
  • Remove hook_page_alter(Might be a part of SCOTCH)
  • D9: Remove preprocess and template preprocess

TWIG Other Wins

  • In-browser template editing finally safe with TWIG(think Contemplate)
  • TWIG can be used in non PHP front ends. Javascript for example
  • Two way com between UI and code
  • Customize your TWIG settings
  • Prints theme debug info in the HTML
  • Auto-refresh / caching in your settings
  • Extensions: filter and functions are easy to call in TWIG
  • Markup utility functions: You can write a template function but you don’t need to
  • Converting Drupal 7 modules to Drupal 8 TWIG theme with Twigifer module(currently in sandbox)
  • Convert all core *.tpl.php templates to Twig as singular patch drupal.org/node/1987510

What are you waiting for? Subscribe already.

Published by Bob Kepford

Powered by Drupal