Why Twig in 2019?
Pros
● Written in PHP
● Easy to learn
● Fast
● Secure
● Flexible
Slide 6
Slide 6 text
Why Twig in 2019?
Used by many Open-Source projects like
Slide 7
Slide 7 text
Why Twig in 2019?
Pros
● Written in PHP
● Easy to learn
● Fast
● Secure
● Flexible
● Mature & popular
● Clean errors
● Good support
Slide 8
Slide 8 text
Why Twig in 2019?
Pros Cons
● Written in PHP
● Easy to learn
● Fast
● Secure
● Flexible
● Mature & popular
● Clean errors
● Good support
● Easy to mess up in a complex project
● Allows too much
Slide 9
Slide 9 text
Why am I talking about Twig?
Slide 10
Slide 10 text
Page Templates
At OroCommerce Twig is Used for
Email Templates
CMS Pages
Slide 11
Slide 11 text
Product Listing Page in OroCommerce
Slide 12
Slide 12 text
Product Listing Page Controller in OroCommerce
Slide 13
Slide 13 text
Product Listing Page Controller in OroCommerce
Slide 14
Slide 14 text
Typical OroCommerce Project
Vendor packages An application (src/)
● 2500+ blocks in 1500+ templates
● 250+ macros
● 250+ functions
● 100+ filters
● 300+ blocks
● in 150+ templates
Slide 15
Slide 15 text
How to Organize Twig Templates in a Big Project?
Complexity
Extensibility
Slide 16
Slide 16 text
Complexity
Slide 17
Slide 17 text
Inheritance vs Includes
Slide 18
Slide 18 text
Macros vs Includes
Slide 19
Slide 19 text
Twig Functions vs Sub-Requests
Slide 20
Slide 20 text
Extensibility
Slide 21
Slide 21 text
Allow Adding Fields to the User Profile from an Extension
Slide 22
Slide 22 text
Rendering
Slide 23
Slide 23 text
Rendering
Slide 24
Slide 24 text
Calling Event Dispatcher from the Template
Slide 25
Slide 25 text
Calling Event Dispatcher from the Template
Slide 26
Slide 26 text
Calling Event Dispatcher from the Template
Slide 27
Slide 27 text
Calling Event Dispatcher from the Template
Slide 28
Slide 28 text
Placeholders
Slide 29
Slide 29 text
Placeholders
Slide 30
Slide 30 text
Placeholders
Slide 31
Slide 31 text
Placeholders
Slide 32
Slide 32 text
Placeholders
Slide 33
Slide 33 text
Placeholders
Slide 34
Slide 34 text
No content
Slide 35
Slide 35 text
How Many Placeholders Do We Need for PLP?
Slide 36
Slide 36 text
www.oroinc.com
Layout Tree
Tree Representation of a Page:
#7 Twig Inspector
Find twig templates and blocks used for rendering HTML pages
https://github.com/oroinc/twig-inspector
● Comments with template and block names
● Visual navigation
● Open the template in your favorite IDE
Slide 62
Slide 62 text
Summary
Pros
1. Easy to learn
2. Fast
3. Secure
4. Flexible
5. Clear errors
6. Mature & Popular
7. Good support
8. Suitable for big & complex projects
Slide 63
Slide 63 text
Summary
Cons
1. Easy to mess up in a complex project. Easy to navigate.
2. Allows too much. Easy to limit the functionality.
Slide 64
Slide 64 text
Twig 3 is Released
● A ton of small tweaks
● Better error messages
● Better performance
● Better consistency
● Cleaner code
To upgrade just update the namespaces