SlideShare a Scribd company logo
1 of 41
Download to read offline
Twig
&
Drupal 8
Joonas Pajunen
• Fraktio Oy
• Symfony2 Developer
• Twitter: joonsp
Arto Iijalainen
• Druid Oy
• Drupal backend developer
• Drupal.org: Sir-Arturio
• Twitter: arto_iijalainen
Twig
Overview
• Twig in general
• Why Twig is in Drupal 8?
• Twig’s solutions to Drupal’s problems
• Current state of the project & conclusion
Templating engine
• Used in Symfony and other projects
• Twig is not a Symfony component
• Inspired by Django, originally by Armin Ronacher, via and maintained by Fabien Potencier
<body>
<ul id="navigation">
{% for item in navigation %}
<li><a href="{{ item.href }}">{{ item.caption }}</a></li>
{% endfor %}
</ul>
<h1>My Webpage</h1>
{{ a_variable }}
{# <p> unimplemented feature </p> #}
</body>
Syntax
<body>
<ul id="navigation">
{% for item in navigation %}
<li><a href="{{ item.href }}">{{ item.caption }}</a></li>
{% endfor %}
</ul>
<h1>My Webpage</h1>
{{ a_variable }}
{# <p> unimplemented feature </p> #}
</body>
• print {{ }}
Syntax
<body>
<ul id="navigation">
{% for item in navigation %}
<li><a href="{{ item.href }}">{{ item.caption }}</a></li>
{% endfor %}
</ul>
<h1>My Webpage</h1>
{{ a_variable }}
{# <p> unimplemented feature </p> #}
</body>
• print {{ }}
• execute statements {% %}
Syntax
<body>
<ul id="navigation">
{% for item in navigation %}
<li><a href="{{ item.href }}">{{ item.caption }}</a></li>
{% endfor %}
</ul>
<h1>My Webpage</h1>
{{ a_variable }}
{# <p> unimplemented feature </p> #}
</body>
• print {{ }}
• execute statements {% %}
• comment {# #}
Syntax
Language features
• control structures
• tests
• variables
• logic
• math
<ul>
{% for user in users %}
{% if loop.index is divisibleby(2) and loop.length < 2 %}
<li class=”even”>
{% else%}
<li class=”odd”>
{% endif %}
{{ user.username }}
</li>
{% else %}
<li>no users</li>
{% endfor %}
</ul>
Variable access
• array key
• object property
• getBar or isBar function
{{ foo.bar }}
Composability
• extends
• include
• use
• block
{# base.html.twig #}
<head>
{% block head %}
{% endblock %}
</head>
<body>
<div id="content">
{% block content %}{% endblock %}
</div>
</div>
{# page.html.twig #}
{% extends "base.html.twig" %}
{% block content %}
<h1>Index</h1>
<p class="important">
Welcome to my awesome homepage.
</p>
{% include "footer.html.twig" %}
{% endblock %}
Filters, functions
{{ post.published_at|date("m/d/Y") }}
{{ [“seppo”,“kimmo”]|first|upper }} -> SEPPO
{{ random(['apple', 'orange', 'citrus']) }}
Extensibility
• custom functions, tags, filters
• can override and customize syntax
class MoneyExtension extends Twig_Extension
{
    public function getFunctions() {
        return array(
            'cents_to_euros' => new Twig_Function_Method($this, 'centsToEuros')
        );
    }
    public function centsToEuros($cents) {
             return round($cents/100, 2);
    }
    public function getName() {
        return 'money';
    }
}
Example: creating a custom function
$twig = new Twig_Environment($loader);
$twig->addExtension(new MoneyExtension());
{{ money(250) }} €
becomes:
2.5 €
Example: creating a custom function (usage)
Speed
• parsed -> optimized php -> cached
• C-extension available
Documentation
• Extensive documentation available!
• http://twig.sensiolabs.org/documentation
Good IDE highlight support
• phpstorm
• netbeans
• eclipse
• sublime text
• notepad++
• vim
• textmate
• etc …
Why
D8
+ ?
New theme layer!
D8
Why do we need a new theme layer?
What’s wrong with D7’s theme layer?
or
http://www.smile-day.net/wp-content/uploads/2012/03/Winking-Smiley-Face1.jpg
Flaws in D7’s theme layer
• PHPtemplate is insecure
• Template language is Drupal-only (PHPtemplate + drupalisms)
• Lots of different ways to address variables
• Theme system is overly complex
• Two ways of creating markup: templates and theme functions
• Too many and too cluttered templates
PHPtemplate is insecure
<?php
db_query("DROP TABLE {node}");
unlink('sites/default/files/myfilename.pdf');
?>
PHPtemplate is insecure
<?php
db_query("DROP TABLE {node}");
unlink('sites/default/files/myfilename.pdf');
?>
Not possible in Twig! o/
Twig - Security
• autoescape by default
• sandbox
Template language is Drupal-only
Twig is proudly found elsewhere!
No need to reinvent the wheel.
Lots of different ways to address variables
• array key
• object property
• getBar or isBar function
{{ foo.bar }}
• $foo[‘bar’]
• $foo->bar
• $foo->getBar()
$foo->isBar()
PHPtemplate Twig
Theme system is overly complex
http://www.slideshare.net/nyccamp/a-new-theme-layer-for-drupal-8
Theme system is overly complex
http://www.slideshare.net/nyccamp/a-new-theme-layer-for-drupal-8
Two ways of creating markup
theme_admin_view();
admin-view.tpl.php
Only Twig templates left!
admin-view.html.twig
Too many and too cluttered templates
Templates will be cleaned and consolidated
in the refactoring process.
Flaws in D7’s theme layer
• PHPtemplate is insecure
• Template language is Drupal-only (PHPtemplate + drupalisms)
• Lots of different ways to address variables
• Theme system is overly complex
• Two ways of creating markup: templates and theme functions
• Too many and too cluttered templates
}
}
Twig will fix
Theme layer will fix
Current development status
• *DONE* Twig is now an official template engine in D8 core
• *IN PROGRESS* Templates are being converted on Twig
• *WAITING* Twig as a main template engine
• *IN PROGRESS* Markup refactoring
• … Creating Dream Markup
• … Rely on Twig auto-escape
• … Finish template suggenstions
• HELP NEEDED!
Conclusions …
Thanks!

More Related Content

What's hot

Javascript for the c# developer
Javascript for the c# developerJavascript for the c# developer
Javascript for the c# developerSalvatore Fazio
 
Building mobile applications with DrupalGap
Building mobile applications with DrupalGapBuilding mobile applications with DrupalGap
Building mobile applications with DrupalGapAlex S
 
WordPress Theme Development: Part 2
WordPress Theme Development: Part 2WordPress Theme Development: Part 2
WordPress Theme Development: Part 2Josh Lee
 
WordPress Theme Development for Designers
WordPress Theme Development for DesignersWordPress Theme Development for Designers
WordPress Theme Development for Designerselliotjaystocks
 
URUG Ruby on Rails Workshop - Sesssion 5
URUG Ruby on Rails Workshop - Sesssion 5URUG Ruby on Rails Workshop - Sesssion 5
URUG Ruby on Rails Workshop - Sesssion 5jakemallory
 
How does get template part works in twenty ten theme
How does get template part works in twenty ten themeHow does get template part works in twenty ten theme
How does get template part works in twenty ten thememohd rozani abd ghani
 
Drupal 7 Theme System
Drupal 7 Theme SystemDrupal 7 Theme System
Drupal 7 Theme SystemPeter Arato
 
Learning PHP for Drupal Theming, DC Chicago 2009
Learning PHP for Drupal Theming, DC Chicago 2009Learning PHP for Drupal Theming, DC Chicago 2009
Learning PHP for Drupal Theming, DC Chicago 2009Emma Jane Hogbin Westby
 
Create responsive websites with Django, REST and AngularJS
Create responsive websites with Django, REST and AngularJSCreate responsive websites with Django, REST and AngularJS
Create responsive websites with Django, REST and AngularJSHannes Hapke
 
SharePoint & jQuery Guide - SPSNashville 2014
SharePoint & jQuery Guide - SPSNashville 2014SharePoint & jQuery Guide - SPSNashville 2014
SharePoint & jQuery Guide - SPSNashville 2014Mark Rackley
 
The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017Amanda Giles
 
Hybrid Web Applications
Hybrid Web ApplicationsHybrid Web Applications
Hybrid Web ApplicationsJames Da Costa
 
Drupal theming - a practical approach (European Drupal Days 2015)
Drupal theming - a practical approach (European Drupal Days 2015)Drupal theming - a practical approach (European Drupal Days 2015)
Drupal theming - a practical approach (European Drupal Days 2015)Eugenio Minardi
 
Writing a WordPress Theme - HighEdWeb 2013 #WRK2
Writing a WordPress Theme - HighEdWeb 2013 #WRK2Writing a WordPress Theme - HighEdWeb 2013 #WRK2
Writing a WordPress Theme - HighEdWeb 2013 #WRK2Curtiss Grymala
 
Django Overview
Django OverviewDjango Overview
Django OverviewBrian Tol
 

What's hot (20)

Javascript for the c# developer
Javascript for the c# developerJavascript for the c# developer
Javascript for the c# developer
 
Building mobile applications with DrupalGap
Building mobile applications with DrupalGapBuilding mobile applications with DrupalGap
Building mobile applications with DrupalGap
 
WordPress Theme Development: Part 2
WordPress Theme Development: Part 2WordPress Theme Development: Part 2
WordPress Theme Development: Part 2
 
Challenges going mobile
Challenges going mobileChallenges going mobile
Challenges going mobile
 
WordPress Theme Development for Designers
WordPress Theme Development for DesignersWordPress Theme Development for Designers
WordPress Theme Development for Designers
 
Plone 5 theming
Plone 5 themingPlone 5 theming
Plone 5 theming
 
Why Django
Why DjangoWhy Django
Why Django
 
URUG Ruby on Rails Workshop - Sesssion 5
URUG Ruby on Rails Workshop - Sesssion 5URUG Ruby on Rails Workshop - Sesssion 5
URUG Ruby on Rails Workshop - Sesssion 5
 
How does get template part works in twenty ten theme
How does get template part works in twenty ten themeHow does get template part works in twenty ten theme
How does get template part works in twenty ten theme
 
Drupal 7 Theme System
Drupal 7 Theme SystemDrupal 7 Theme System
Drupal 7 Theme System
 
Learning PHP for Drupal Theming, DC Chicago 2009
Learning PHP for Drupal Theming, DC Chicago 2009Learning PHP for Drupal Theming, DC Chicago 2009
Learning PHP for Drupal Theming, DC Chicago 2009
 
Create responsive websites with Django, REST and AngularJS
Create responsive websites with Django, REST and AngularJSCreate responsive websites with Django, REST and AngularJS
Create responsive websites with Django, REST and AngularJS
 
SharePoint & jQuery Guide - SPSNashville 2014
SharePoint & jQuery Guide - SPSNashville 2014SharePoint & jQuery Guide - SPSNashville 2014
SharePoint & jQuery Guide - SPSNashville 2014
 
The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017
 
Git Makes Me Angry Inside
Git Makes Me Angry InsideGit Makes Me Angry Inside
Git Makes Me Angry Inside
 
What's new in D7 Theming?
What's new in D7 Theming?What's new in D7 Theming?
What's new in D7 Theming?
 
Hybrid Web Applications
Hybrid Web ApplicationsHybrid Web Applications
Hybrid Web Applications
 
Drupal theming - a practical approach (European Drupal Days 2015)
Drupal theming - a practical approach (European Drupal Days 2015)Drupal theming - a practical approach (European Drupal Days 2015)
Drupal theming - a practical approach (European Drupal Days 2015)
 
Writing a WordPress Theme - HighEdWeb 2013 #WRK2
Writing a WordPress Theme - HighEdWeb 2013 #WRK2Writing a WordPress Theme - HighEdWeb 2013 #WRK2
Writing a WordPress Theme - HighEdWeb 2013 #WRK2
 
Django Overview
Django OverviewDjango Overview
Django Overview
 

Viewers also liked

Drupal 8 introduction to theming
Drupal 8  introduction to themingDrupal 8  introduction to theming
Drupal 8 introduction to themingBrahampal Singh
 
Drupal 8: Theming. Lviv Drupal Cafe #4
Drupal 8: Theming. Lviv Drupal Cafe #4Drupal 8: Theming. Lviv Drupal Cafe #4
Drupal 8: Theming. Lviv Drupal Cafe #4Pavel Shevchuk
 
Drupal8 theming
Drupal8 themingDrupal8 theming
Drupal8 theminghrisi87
 
Drupal8 themingdeepdive drupaldevdays-montpellier17042015
Drupal8 themingdeepdive drupaldevdays-montpellier17042015Drupal8 themingdeepdive drupaldevdays-montpellier17042015
Drupal8 themingdeepdive drupaldevdays-montpellier17042015Romain Jarraud
 
Ready. Set. Drupal! An Intro to Drupal 8, Part 2
Ready. Set. Drupal! An Intro to Drupal 8, Part 2Ready. Set. Drupal! An Intro to Drupal 8, Part 2
Ready. Set. Drupal! An Intro to Drupal 8, Part 2Acquia
 
[Srijan Wednesday Webinars] Drupal 8: Goodbye to 10 Years of Theming Headaches
[Srijan Wednesday Webinars] Drupal 8: Goodbye to 10 Years of Theming Headaches[Srijan Wednesday Webinars] Drupal 8: Goodbye to 10 Years of Theming Headaches
[Srijan Wednesday Webinars] Drupal 8: Goodbye to 10 Years of Theming HeadachesSrijan Technologies
 

Viewers also liked (7)

Drupal 8 introduction to theming
Drupal 8  introduction to themingDrupal 8  introduction to theming
Drupal 8 introduction to theming
 
Drupal 8: Theming. Lviv Drupal Cafe #4
Drupal 8: Theming. Lviv Drupal Cafe #4Drupal 8: Theming. Lviv Drupal Cafe #4
Drupal 8: Theming. Lviv Drupal Cafe #4
 
Drupal8 theming
Drupal8 themingDrupal8 theming
Drupal8 theming
 
Drupal 8 theming
Drupal 8 themingDrupal 8 theming
Drupal 8 theming
 
Drupal8 themingdeepdive drupaldevdays-montpellier17042015
Drupal8 themingdeepdive drupaldevdays-montpellier17042015Drupal8 themingdeepdive drupaldevdays-montpellier17042015
Drupal8 themingdeepdive drupaldevdays-montpellier17042015
 
Ready. Set. Drupal! An Intro to Drupal 8, Part 2
Ready. Set. Drupal! An Intro to Drupal 8, Part 2Ready. Set. Drupal! An Intro to Drupal 8, Part 2
Ready. Set. Drupal! An Intro to Drupal 8, Part 2
 
[Srijan Wednesday Webinars] Drupal 8: Goodbye to 10 Years of Theming Headaches
[Srijan Wednesday Webinars] Drupal 8: Goodbye to 10 Years of Theming Headaches[Srijan Wednesday Webinars] Drupal 8: Goodbye to 10 Years of Theming Headaches
[Srijan Wednesday Webinars] Drupal 8: Goodbye to 10 Years of Theming Headaches
 

Similar to Twig

Html5 Brown Bag
Html5 Brown BagHtml5 Brown Bag
Html5 Brown Bagstuplum
 
Twig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHPTwig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHPFabien Potencier
 
HTML5, just another presentation :)
HTML5, just another presentation :)HTML5, just another presentation :)
HTML5, just another presentation :)François Massart
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesShabir Ahmad
 
Frontend for developers
Frontend for developersFrontend for developers
Frontend for developersHernan Mammana
 
WordPress-Templates mit Twig erstellen - PHPUGFFM
WordPress-Templates mit Twig erstellen - PHPUGFFMWordPress-Templates mit Twig erstellen - PHPUGFFM
WordPress-Templates mit Twig erstellen - PHPUGFFMWalter Ebert
 
HTML5 & Front-end overview
HTML5 & Front-end overviewHTML5 & Front-end overview
HTML5 & Front-end overviewAshish Mukherjee
 
Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress Maurizio Pelizzone
 
2022 HTML5: The future is now
2022 HTML5: The future is now2022 HTML5: The future is now
2022 HTML5: The future is nowGonzalo Cordero
 
An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to TornadoGavin Roy
 
GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineYared Ayalew
 
Grok Drupal (7) Theming - 2011 Feb update
Grok Drupal (7) Theming - 2011 Feb updateGrok Drupal (7) Theming - 2011 Feb update
Grok Drupal (7) Theming - 2011 Feb updateLaura Scott
 
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)Doris Chen
 
Toutch Jquery Mobile
Toutch Jquery MobileToutch Jquery Mobile
Toutch Jquery MobileJinlong He
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPOscar Merida
 
PHPConf-TW 2012 # Twig
PHPConf-TW 2012 # TwigPHPConf-TW 2012 # Twig
PHPConf-TW 2012 # TwigWake Liu
 
Darwin web standards
Darwin web standardsDarwin web standards
Darwin web standardsJustin Avery
 
Freelancer Weapons of mass productivity
Freelancer Weapons of mass productivityFreelancer Weapons of mass productivity
Freelancer Weapons of mass productivityGregg Coppen
 
Html5 drupal7 with mandakini kumari(1)
Html5 drupal7 with mandakini kumari(1)Html5 drupal7 with mandakini kumari(1)
Html5 drupal7 with mandakini kumari(1)Mandakini Kumari
 

Similar to Twig (20)

Html5 Brown Bag
Html5 Brown BagHtml5 Brown Bag
Html5 Brown Bag
 
Twig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHPTwig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHP
 
HTML5, just another presentation :)
HTML5, just another presentation :)HTML5, just another presentation :)
HTML5, just another presentation :)
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API Changes
 
Frontend for developers
Frontend for developersFrontend for developers
Frontend for developers
 
WordPress-Templates mit Twig erstellen - PHPUGFFM
WordPress-Templates mit Twig erstellen - PHPUGFFMWordPress-Templates mit Twig erstellen - PHPUGFFM
WordPress-Templates mit Twig erstellen - PHPUGFFM
 
HTML5 & Front-end overview
HTML5 & Front-end overviewHTML5 & Front-end overview
HTML5 & Front-end overview
 
Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress
 
2022 HTML5: The future is now
2022 HTML5: The future is now2022 HTML5: The future is now
2022 HTML5: The future is now
 
An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to Tornado
 
GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App Engine
 
Grok Drupal (7) Theming - 2011 Feb update
Grok Drupal (7) Theming - 2011 Feb updateGrok Drupal (7) Theming - 2011 Feb update
Grok Drupal (7) Theming - 2011 Feb update
 
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
 
Toutch Jquery Mobile
Toutch Jquery MobileToutch Jquery Mobile
Toutch Jquery Mobile
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHP
 
Intro to HTML
Intro to HTMLIntro to HTML
Intro to HTML
 
PHPConf-TW 2012 # Twig
PHPConf-TW 2012 # TwigPHPConf-TW 2012 # Twig
PHPConf-TW 2012 # Twig
 
Darwin web standards
Darwin web standardsDarwin web standards
Darwin web standards
 
Freelancer Weapons of mass productivity
Freelancer Weapons of mass productivityFreelancer Weapons of mass productivity
Freelancer Weapons of mass productivity
 
Html5 drupal7 with mandakini kumari(1)
Html5 drupal7 with mandakini kumari(1)Html5 drupal7 with mandakini kumari(1)
Html5 drupal7 with mandakini kumari(1)
 

Recently uploaded

Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 

Recently uploaded (20)

Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

Twig

  • 2. Joonas Pajunen • Fraktio Oy • Symfony2 Developer • Twitter: joonsp
  • 3. Arto Iijalainen • Druid Oy • Drupal backend developer • Drupal.org: Sir-Arturio • Twitter: arto_iijalainen
  • 5. Overview • Twig in general • Why Twig is in Drupal 8? • Twig’s solutions to Drupal’s problems • Current state of the project & conclusion
  • 6. Templating engine • Used in Symfony and other projects • Twig is not a Symfony component • Inspired by Django, originally by Armin Ronacher, via and maintained by Fabien Potencier
  • 7. <body> <ul id="navigation"> {% for item in navigation %} <li><a href="{{ item.href }}">{{ item.caption }}</a></li> {% endfor %} </ul> <h1>My Webpage</h1> {{ a_variable }} {# <p> unimplemented feature </p> #} </body> Syntax
  • 8. <body> <ul id="navigation"> {% for item in navigation %} <li><a href="{{ item.href }}">{{ item.caption }}</a></li> {% endfor %} </ul> <h1>My Webpage</h1> {{ a_variable }} {# <p> unimplemented feature </p> #} </body> • print {{ }} Syntax
  • 9. <body> <ul id="navigation"> {% for item in navigation %} <li><a href="{{ item.href }}">{{ item.caption }}</a></li> {% endfor %} </ul> <h1>My Webpage</h1> {{ a_variable }} {# <p> unimplemented feature </p> #} </body> • print {{ }} • execute statements {% %} Syntax
  • 10. <body> <ul id="navigation"> {% for item in navigation %} <li><a href="{{ item.href }}">{{ item.caption }}</a></li> {% endfor %} </ul> <h1>My Webpage</h1> {{ a_variable }} {# <p> unimplemented feature </p> #} </body> • print {{ }} • execute statements {% %} • comment {# #} Syntax
  • 11. Language features • control structures • tests • variables • logic • math
  • 12. <ul> {% for user in users %} {% if loop.index is divisibleby(2) and loop.length < 2 %} <li class=”even”> {% else%} <li class=”odd”> {% endif %} {{ user.username }} </li> {% else %} <li>no users</li> {% endfor %} </ul>
  • 13. Variable access • array key • object property • getBar or isBar function {{ foo.bar }}
  • 15. {# base.html.twig #} <head> {% block head %} {% endblock %} </head> <body> <div id="content"> {% block content %}{% endblock %} </div> </div> {# page.html.twig #} {% extends "base.html.twig" %} {% block content %} <h1>Index</h1> <p class="important"> Welcome to my awesome homepage. </p> {% include "footer.html.twig" %} {% endblock %}
  • 16. Filters, functions {{ post.published_at|date("m/d/Y") }} {{ [“seppo”,“kimmo”]|first|upper }} -> SEPPO {{ random(['apple', 'orange', 'citrus']) }}
  • 17. Extensibility • custom functions, tags, filters • can override and customize syntax
  • 18. class MoneyExtension extends Twig_Extension {     public function getFunctions() {         return array(             'cents_to_euros' => new Twig_Function_Method($this, 'centsToEuros')         );     }     public function centsToEuros($cents) {              return round($cents/100, 2);     }     public function getName() {         return 'money';     } } Example: creating a custom function
  • 19. $twig = new Twig_Environment($loader); $twig->addExtension(new MoneyExtension()); {{ money(250) }} € becomes: 2.5 € Example: creating a custom function (usage)
  • 20. Speed • parsed -> optimized php -> cached • C-extension available
  • 21. Documentation • Extensive documentation available! • http://twig.sensiolabs.org/documentation
  • 22. Good IDE highlight support • phpstorm • netbeans • eclipse • sublime text • notepad++ • vim • textmate • etc …
  • 25. Why do we need a new theme layer? What’s wrong with D7’s theme layer? or
  • 27. Flaws in D7’s theme layer • PHPtemplate is insecure • Template language is Drupal-only (PHPtemplate + drupalisms) • Lots of different ways to address variables • Theme system is overly complex • Two ways of creating markup: templates and theme functions • Too many and too cluttered templates
  • 28. PHPtemplate is insecure <?php db_query("DROP TABLE {node}"); unlink('sites/default/files/myfilename.pdf'); ?>
  • 29.
  • 30. PHPtemplate is insecure <?php db_query("DROP TABLE {node}"); unlink('sites/default/files/myfilename.pdf'); ?> Not possible in Twig! o/
  • 31. Twig - Security • autoescape by default • sandbox
  • 32. Template language is Drupal-only Twig is proudly found elsewhere! No need to reinvent the wheel.
  • 33. Lots of different ways to address variables • array key • object property • getBar or isBar function {{ foo.bar }} • $foo[‘bar’] • $foo->bar • $foo->getBar() $foo->isBar() PHPtemplate Twig
  • 34. Theme system is overly complex http://www.slideshare.net/nyccamp/a-new-theme-layer-for-drupal-8
  • 35. Theme system is overly complex http://www.slideshare.net/nyccamp/a-new-theme-layer-for-drupal-8
  • 36. Two ways of creating markup theme_admin_view(); admin-view.tpl.php Only Twig templates left! admin-view.html.twig
  • 37. Too many and too cluttered templates Templates will be cleaned and consolidated in the refactoring process.
  • 38. Flaws in D7’s theme layer • PHPtemplate is insecure • Template language is Drupal-only (PHPtemplate + drupalisms) • Lots of different ways to address variables • Theme system is overly complex • Two ways of creating markup: templates and theme functions • Too many and too cluttered templates } } Twig will fix Theme layer will fix
  • 39. Current development status • *DONE* Twig is now an official template engine in D8 core • *IN PROGRESS* Templates are being converted on Twig • *WAITING* Twig as a main template engine • *IN PROGRESS* Markup refactoring • … Creating Dream Markup • … Rely on Twig auto-escape • … Finish template suggenstions • HELP NEEDED!