4. Wizzlern
‣ 100% Drupal
‣ Drupal training and consultancy
‣ Front-, backend-development
‣ Drupal introduction and editors
‣ System management
‣ Since 2009
‣ Involved with the Drupal community
4
6. A bit of history
‣ Dec. 2011: Frustrations over D7 theme
system boiled up (again)
‣ Feb./March 2012: Alternatives discussed
‣ April 2012: Code sprints
‣ June 2012: Twig engine landed in core
6
7. Why change?
‣ Inconsistent data structure
(Render Array, Markup, Wrappers)
‣ Many levels of processing ((pre)process,
(pre)render, theme-function or template)
‣ It’s so hard to make changes.
‣ Problem summary:
http://jacine.net/post/19652705220/theme-system
7
8. And the winner is...
‣ Twig is a modern template engine for PHP
‣ Fast, secure, flexible
8
Twig
9. Why Twig?
‣ Pros
‣ Mature, well-tested, used in other major
platforms too (Zend Framework, CodeIgniter,
CakePHP)
‣ Improved security
‣ Easy syntax
‣ Cons
‣ New language to lean, extra learning curve
‣ Migration required by module maintainers and
site builders
9
10. More improvements
‣ Cleaner templates
‣ Consistent method to override output
‣ Debugging built-in
‣ IDE support
‣ A bit quicker theme development (my
prediction)
10
11. And more...
‣ Performance: Minimal changes expected.
‣ Learning curve:
The easy got easier (overrides) but
the hard is still hard (Render Array).
‣ Object oriented
11
18. Syntax
‣ {{ ... }} Prints something
‣ Prints a variabele or the result of an
expression
‣ Prints text, but also Render Array content.
‣ {% ... %} Controls something
‣ Controls the execution of a template, e.g.
conditions and loops
‣ {# ... #} Does nothing
‣ Descriptions and comments
18
29. Debugging Twig
{{ dump(...) }}
‣ Twig options in settings.php:
‣ $settings['twig_debug']
‣ $settings['twig_auto_reload']
‣ $settings['twig_cache']
‣ About debugging variables in Twig templates:
http://drupal.org/node/1906780
29
30. settings.php
$settings['twig_debug'] = TRUE;
Output in DOM:
<!-- THEME DEBUG -->
<!-- CALL: theme('region') -->
<!-- FILE NAME SUGGESTIONS:
* region--content.html.twig
x region.html.twig
-->
‣ Only for templates used in your theme.
30
36. Theme layer changes
‣ Your preprocess functions now go into:
THEMENAME.theme file (#1967614)
‣ Options to override or delete CSS files
added by modules or base themes
(#1876600).
‣ More theme functions accept render
elements. e.g. theme_item_list(), l() (#891112,
#1987114)
36
37. D8 Mobile Initiative
‣ Responsive design
‣ Visual breakpoint editor
‣ Responsive tables
‣ <picture> element added
‣ jQuery 1.9 included
‣ IE8 no longer supported
‣ Improved CSS standards, incl. SMACCS
37
38. That’s all folks
‣ Twig documentation:
http://twig.sensiolabs.org/doc/templates.html
‣ Contribute to Drupal 8 twig development:
http://lb.cm/twig
‣ These slides:
http://wizzlern.nl/drupaljam2013-twig
38
39. This work is licensed under the Creative Commons
Attribution-NonCommercial-ShareAlike 3.0 Unported
License.To view a copy of this license, visit http://
creativecommons.org/licenses/by-nc-sa/3.0/.
39
http://wizzlern.nl
Twitter: @wizzlern