ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
TWIG
About Me


           Wake Liu


wake.gs@gmail.com
Before the session starts
Do I need a template
      engine?
PHP is the most
powerful template
     engine
PHPConf-TW 2012 # Twig
So, we really need a
 template engine ?
TWIG
Performance
? Compile & cache
? PHP Extension - Twig_Template::getAttribute()
? APC & Memcached
How it feels to use Twig
Clean and Beautiful
Variables
?   <?php echo $name; ?>   ?   {{ name }}

?   <?php echo             ?   {{ member.nickname }}
    $member->nickname;
    ?>                     ?   {{ member[¡®nickname¡¯] }}

?   <?php                  ?   {{
    echo                       member
    $member[¡®nickname¡¯];         ? member.nickname
    ?>                           : ¡®Guest¡¯
                               }}
Filters / Functions
? <?php echo nl2br ($content); ?>
? <?php echo html_entity_decode ($content); ?>
? <?php echo rand(0, 10); ?>
?   {{ content|nl2br }}

?   {{ content|raw }}     {{ content|nl2br|length }}


?   {{ random(10) }}
Logic & Loop

?   {% if %} {% elseif %} {% else %} {% endif %}



?   {% for key, value in data %}   {% endfor %}



?   {% set name = ¡®wake¡¯ %}
Organizational and
    reusable
Extends
layout.html
 <!DOCTYPE html>
                                        guest.html
<html lang="en">
<head>
 <meta charset="utf-8">                 {% extends layout.html %}
 <title>The HTML5 Herald</title>
</head>
<body>


   {% block wrapper %}
    default content
                                        member.html
   {% endblock %}                       {% extends layout.html %}
</body>
</html>
Horizontal reuse
                        page.html
navigator.html
                         {% use navigator.html %}
                         {% use login.html %}
{% block navigator %}   <div class=/slideshow/phpconftw-2012-twig/15031060/¡±wrapper/slideshow/phpconftw-2012-twig/15031060/¡±>
                         <div class=/slideshow/phpconftw-2012-twig/15031060/¡±navigator/slideshow/phpconftw-2012-twig/15031060/¡±>

                           {{ block (¡®navigator¡¯) }}
login.html               </div>

                         <div class=/slideshow/phpconftw-2012-twig/15031060/¡±login/slideshow/phpconftw-2012-twig/15031060/¡±>

                           {{ block (¡®login¡¯) }}
{% block login %}        </div>
                        </div>
Expandable
Filter, Function, Macro
       and others
The role of Twig
Template engine
View helper
MVC
Controller
                        Control ( Logic / Loop )

                    {
   C
             View       Data handling ( Filters / Functions )
              V         View binding ( Structures / Macros )
  Model

   M
Hmm, it looks not bad,
        but ...
......

 VS
Some more
interesting things
Photo URL passing
                             photo.html
original data                <img src=/slideshow/phpconftw-2012-twig/15031060/¡±


http://www/:size/photo.jpg    {{ url | image_to_large }}
                              /slideshow/phpconftw-2012-twig/15031060/¡±>




php de?ne                    Twig - addFilter
_LARGE_PHOTO ¡®L¡¯
_SMALL_PHOTO ¡®S¡¯              image_to_*
Template driven
member.php
                                  A.html
class Member {
                                  <div>


    function __get ($name) {       {{ member.age }}
      $loader = ¡°_load$name/slideshow/phpconftw-2012-twig/15031060/¡±;     </div>


      return $this->$loader ();
    }                             B.html
    function _loadAge () {        <div>


      // load from database        {{ member.age }}
    }                             </div>


}
Thank you

 Q &A

More Related Content

What's hot (18)

jQuery Best Practice
jQuery Best Practice jQuery Best Practice
jQuery Best Practice
chandrashekher786
?
Dundee University HackU 2013 - Mojito
Dundee University HackU 2013 - MojitoDundee University HackU 2013 - Mojito
Dundee University HackU 2013 - Mojito
smartads
?
JQuery
JQueryJQuery
JQuery
Jussi Pohjolainen
?
Short intro to JQuery and Modernizr
Short intro to JQuery and ModernizrShort intro to JQuery and Modernizr
Short intro to JQuery and Modernizr
Jussi Pohjolainen
?
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
Nick Lee
?
Backbone
BackboneBackbone
Backbone
Glenn De Backer
?
Backbone js in drupal core
Backbone js in drupal coreBackbone js in drupal core
Backbone js in drupal core
Marcin Wosinek
?
Introducing jQuery
Introducing jQueryIntroducing jQuery
Introducing jQuery
Wildan Maulana
?
Optimizing Magento by Preloading Data
Optimizing Magento by Preloading DataOptimizing Magento by Preloading Data
Optimizing Magento by Preloading Data
Ivan Chepurnyi
?
Using of TDD practices for Magento
Using of TDD practices for MagentoUsing of TDD practices for Magento
Using of TDD practices for Magento
Ivan Chepurnyi
?
jQuery
jQueryjQuery
jQuery
Mohammed Arif
?
Learning the basics of the Drupal API
Learning the basics of the Drupal APILearning the basics of the Drupal API
Learning the basics of the Drupal API
Alexandru Badiu
?
AngularJS and SPA
AngularJS and SPAAngularJS and SPA
AngularJS and SPA
Lorenzo Dematt¨¦
?
Jquery
JqueryJquery
Jquery
baabtra.com - No. 1 supplier of quality freshers
?
In-depth changes to Drupal 8 javascript
In-depth changes to Drupal 8 javascriptIn-depth changes to Drupal 8 javascript
In-depth changes to Drupal 8 javascript
Th¨¦odore Biadala
?
Django Templates
Django TemplatesDjango Templates
Django Templates
Willy Liu
?
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
Ayes Chinmay
?
Get AngularJS Started!
Get AngularJS Started!Get AngularJS Started!
Get AngularJS Started!
Dzmitry Ivashutsin
?

Similar to PHPConf-TW 2012 # Twig (20)

The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
fishwarter
?
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
fishwarter
?
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
fishwarter
?
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
fishwarter
?
Django Rest Framework and React and Redux, Oh My!
Django Rest Framework and React and Redux, Oh My!Django Rest Framework and React and Redux, Oh My!
Django Rest Framework and React and Redux, Oh My!
Eric Palakovich Carr
?
Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Php
funkatron
?
Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101
Ted Kulp
?
Yii Introduction
Yii IntroductionYii Introduction
Yii Introduction
Jason Ragsdale
?
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
Richard Leland
?
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
Richard Leland
?
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
Richard Leland
?
Django ?Class-based views (Slovenian)
Django ?Class-based views (Slovenian)Django ?Class-based views (Slovenian)
Django ?Class-based views (Slovenian)
Luka Zakraj?ek
?
Templates
TemplatesTemplates
Templates
soon
?
Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress
Maurizio Pelizzone
?
Flask ¨C Python
Flask ¨C PythonFlask ¨C Python
Flask ¨C Python
Max Claus Nunes
?
TurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsTurboGears2 Pluggable Applications
TurboGears2 Pluggable Applications
Alessandro Molina
?
Ç°¶Ë¸ÅÊö
Ç°¶Ë¸ÅÊöÇ°¶Ë¸ÅÊö
Ç°¶Ë¸ÅÊö
Ethan Zhang
?
Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4
DEVCON
?
OSDC 2009 Rails Turtorial
OSDC 2009 Rails TurtorialOSDC 2009 Rails Turtorial
OSDC 2009 Rails Turtorial
Yi-Ting Cheng
?
8 things to know about theming in drupal 8
8 things to know about theming in drupal 88 things to know about theming in drupal 8
8 things to know about theming in drupal 8
Logan Farr
?
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
fishwarter
?
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
fishwarter
?
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
fishwarter
?
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
fishwarter
?
Django Rest Framework and React and Redux, Oh My!
Django Rest Framework and React and Redux, Oh My!Django Rest Framework and React and Redux, Oh My!
Django Rest Framework and React and Redux, Oh My!
Eric Palakovich Carr
?
Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Php
funkatron
?
Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101
Ted Kulp
?
Django ?Class-based views (Slovenian)
Django ?Class-based views (Slovenian)Django ?Class-based views (Slovenian)
Django ?Class-based views (Slovenian)
Luka Zakraj?ek
?
Templates
TemplatesTemplates
Templates
soon
?
Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress
Maurizio Pelizzone
?
TurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsTurboGears2 Pluggable Applications
TurboGears2 Pluggable Applications
Alessandro Molina
?
Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4
DEVCON
?
OSDC 2009 Rails Turtorial
OSDC 2009 Rails TurtorialOSDC 2009 Rails Turtorial
OSDC 2009 Rails Turtorial
Yi-Ting Cheng
?
8 things to know about theming in drupal 8
8 things to know about theming in drupal 88 things to know about theming in drupal 8
8 things to know about theming in drupal 8
Logan Farr
?

Recently uploaded (20)

202408_JAWSPANKRATION_Introduction_of_Minaden.pdf
202408_JAWSPANKRATION_Introduction_of_Minaden.pdf202408_JAWSPANKRATION_Introduction_of_Minaden.pdf
202408_JAWSPANKRATION_Introduction_of_Minaden.pdf
NTTDOCOMO-ServiceInnovation
?
Sugarlab AI: How Much Does an XXX AI Porn Generator Cost in 2025
Sugarlab AI: How Much Does an XXX AI Porn Generator Cost in 2025Sugarlab AI: How Much Does an XXX AI Porn Generator Cost in 2025
Sugarlab AI: How Much Does an XXX AI Porn Generator Cost in 2025
Sugarlab AI
?
Commit Conf 2025 Bitnami Charts with Kubescape
Commit Conf 2025 Bitnami Charts with KubescapeCommit Conf 2025 Bitnami Charts with Kubescape
Commit Conf 2025 Bitnami Charts with Kubescape
Alfredo Garc¨ªa Lavilla
?
Threat Modeling a Batch Job System - AWS Security Community Day
Threat Modeling a Batch Job System - AWS Security Community DayThreat Modeling a Batch Job System - AWS Security Community Day
Threat Modeling a Batch Job System - AWS Security Community Day
Teri Radichel
?
2025-04-05 - Block71 Event - The Landscape of GenAI and Ecosystem.pdf
2025-04-05 - Block71 Event - The Landscape of GenAI and Ecosystem.pdf2025-04-05 - Block71 Event - The Landscape of GenAI and Ecosystem.pdf
2025-04-05 - Block71 Event - The Landscape of GenAI and Ecosystem.pdf
Ivan Tang
?
CIOs Speak Out - A Research Series by Jasper Colin
CIOs Speak Out - A Research Series by Jasper ColinCIOs Speak Out - A Research Series by Jasper Colin
CIOs Speak Out - A Research Series by Jasper Colin
Jasper Colin
?
Solana Developer Hiring for Enterprises Key Considerations.pdf
Solana Developer Hiring for Enterprises Key Considerations.pdfSolana Developer Hiring for Enterprises Key Considerations.pdf
Solana Developer Hiring for Enterprises Key Considerations.pdf
Lisa ward
?
All-Data, Any-AI Integration: FME & Amazon Bedrock in the Real-World
All-Data, Any-AI Integration: FME & Amazon Bedrock in the Real-WorldAll-Data, Any-AI Integration: FME & Amazon Bedrock in the Real-World
All-Data, Any-AI Integration: FME & Amazon Bedrock in the Real-World
Safe Software
?
Mastering Azure Durable Functions - Building Resilient and Scalable Workflows
Mastering Azure Durable Functions - Building Resilient and Scalable WorkflowsMastering Azure Durable Functions - Building Resilient and Scalable Workflows
Mastering Azure Durable Functions - Building Resilient and Scalable Workflows
Callon Campbell
?
Cybersecurity-Threat-Landscape-March-31-April-7-2025.pdf
Cybersecurity-Threat-Landscape-March-31-April-7-2025.pdfCybersecurity-Threat-Landscape-March-31-April-7-2025.pdf
Cybersecurity-Threat-Landscape-March-31-April-7-2025.pdf
Joe Shenouda
?
Microsoft Digital Defense Report 2024 .pdf
Microsoft Digital Defense Report 2024 .pdfMicrosoft Digital Defense Report 2024 .pdf
Microsoft Digital Defense Report 2024 .pdf
Abhishek Agarwal
?
Recruiting Tech: A Look at Why AI is Actually OG
Recruiting Tech: A Look at Why AI is Actually OGRecruiting Tech: A Look at Why AI is Actually OG
Recruiting Tech: A Look at Why AI is Actually OG
Matt Charney
?
Columbia Weather Systems - Product Overview
Columbia Weather Systems - Product OverviewColumbia Weather Systems - Product Overview
Columbia Weather Systems - Product Overview
Columbia Weather Systems
?
STRING FUNCTIONS IN JAVA BY N SARATH KUMAR
STRING FUNCTIONS IN JAVA BY N SARATH KUMARSTRING FUNCTIONS IN JAVA BY N SARATH KUMAR
STRING FUNCTIONS IN JAVA BY N SARATH KUMAR
Sarathkumar Narsupalli
?
GDG Cloud Southlake #41: Shay Levi: Beyond the Hype:How Enterprises Are Using AI
GDG Cloud Southlake #41: Shay Levi: Beyond the Hype:How Enterprises Are Using AIGDG Cloud Southlake #41: Shay Levi: Beyond the Hype:How Enterprises Are Using AI
GDG Cloud Southlake #41: Shay Levi: Beyond the Hype:How Enterprises Are Using AI
James Anderson
?
Smarter RAG Pipelines: Scaling Search with Milvus and Feast
Smarter RAG Pipelines: Scaling Search with Milvus and FeastSmarter RAG Pipelines: Scaling Search with Milvus and Feast
Smarter RAG Pipelines: Scaling Search with Milvus and Feast
Zilliz
?
Getting the Best of TrueDEM ¨C April News & Updates
Getting the Best of TrueDEM ¨C April News & UpdatesGetting the Best of TrueDEM ¨C April News & Updates
Getting the Best of TrueDEM ¨C April News & Updates
panagenda
?
The metaverse : A Digital Transformation
The metaverse : A Digital TransformationThe metaverse : A Digital Transformation
The metaverse : A Digital Transformation
matlotloatang03
?
How Telemedicine App Development is Revolutionizing Virtual Care.pptx
How Telemedicine App Development is Revolutionizing Virtual Care.pptxHow Telemedicine App Development is Revolutionizing Virtual Care.pptx
How Telemedicine App Development is Revolutionizing Virtual Care.pptx
Dash Technologies Inc
?
Artificial Neural Networks, basics, its variations and examples
Artificial Neural Networks, basics, its variations and examplesArtificial Neural Networks, basics, its variations and examples
Artificial Neural Networks, basics, its variations and examples
anandsimple
?
Sugarlab AI: How Much Does an XXX AI Porn Generator Cost in 2025
Sugarlab AI: How Much Does an XXX AI Porn Generator Cost in 2025Sugarlab AI: How Much Does an XXX AI Porn Generator Cost in 2025
Sugarlab AI: How Much Does an XXX AI Porn Generator Cost in 2025
Sugarlab AI
?
Threat Modeling a Batch Job System - AWS Security Community Day
Threat Modeling a Batch Job System - AWS Security Community DayThreat Modeling a Batch Job System - AWS Security Community Day
Threat Modeling a Batch Job System - AWS Security Community Day
Teri Radichel
?
2025-04-05 - Block71 Event - The Landscape of GenAI and Ecosystem.pdf
2025-04-05 - Block71 Event - The Landscape of GenAI and Ecosystem.pdf2025-04-05 - Block71 Event - The Landscape of GenAI and Ecosystem.pdf
2025-04-05 - Block71 Event - The Landscape of GenAI and Ecosystem.pdf
Ivan Tang
?
CIOs Speak Out - A Research Series by Jasper Colin
CIOs Speak Out - A Research Series by Jasper ColinCIOs Speak Out - A Research Series by Jasper Colin
CIOs Speak Out - A Research Series by Jasper Colin
Jasper Colin
?
Solana Developer Hiring for Enterprises Key Considerations.pdf
Solana Developer Hiring for Enterprises Key Considerations.pdfSolana Developer Hiring for Enterprises Key Considerations.pdf
Solana Developer Hiring for Enterprises Key Considerations.pdf
Lisa ward
?
All-Data, Any-AI Integration: FME & Amazon Bedrock in the Real-World
All-Data, Any-AI Integration: FME & Amazon Bedrock in the Real-WorldAll-Data, Any-AI Integration: FME & Amazon Bedrock in the Real-World
All-Data, Any-AI Integration: FME & Amazon Bedrock in the Real-World
Safe Software
?
Mastering Azure Durable Functions - Building Resilient and Scalable Workflows
Mastering Azure Durable Functions - Building Resilient and Scalable WorkflowsMastering Azure Durable Functions - Building Resilient and Scalable Workflows
Mastering Azure Durable Functions - Building Resilient and Scalable Workflows
Callon Campbell
?
Cybersecurity-Threat-Landscape-March-31-April-7-2025.pdf
Cybersecurity-Threat-Landscape-March-31-April-7-2025.pdfCybersecurity-Threat-Landscape-March-31-April-7-2025.pdf
Cybersecurity-Threat-Landscape-March-31-April-7-2025.pdf
Joe Shenouda
?
Microsoft Digital Defense Report 2024 .pdf
Microsoft Digital Defense Report 2024 .pdfMicrosoft Digital Defense Report 2024 .pdf
Microsoft Digital Defense Report 2024 .pdf
Abhishek Agarwal
?
Recruiting Tech: A Look at Why AI is Actually OG
Recruiting Tech: A Look at Why AI is Actually OGRecruiting Tech: A Look at Why AI is Actually OG
Recruiting Tech: A Look at Why AI is Actually OG
Matt Charney
?
STRING FUNCTIONS IN JAVA BY N SARATH KUMAR
STRING FUNCTIONS IN JAVA BY N SARATH KUMARSTRING FUNCTIONS IN JAVA BY N SARATH KUMAR
STRING FUNCTIONS IN JAVA BY N SARATH KUMAR
Sarathkumar Narsupalli
?
GDG Cloud Southlake #41: Shay Levi: Beyond the Hype:How Enterprises Are Using AI
GDG Cloud Southlake #41: Shay Levi: Beyond the Hype:How Enterprises Are Using AIGDG Cloud Southlake #41: Shay Levi: Beyond the Hype:How Enterprises Are Using AI
GDG Cloud Southlake #41: Shay Levi: Beyond the Hype:How Enterprises Are Using AI
James Anderson
?
Smarter RAG Pipelines: Scaling Search with Milvus and Feast
Smarter RAG Pipelines: Scaling Search with Milvus and FeastSmarter RAG Pipelines: Scaling Search with Milvus and Feast
Smarter RAG Pipelines: Scaling Search with Milvus and Feast
Zilliz
?
Getting the Best of TrueDEM ¨C April News & Updates
Getting the Best of TrueDEM ¨C April News & UpdatesGetting the Best of TrueDEM ¨C April News & Updates
Getting the Best of TrueDEM ¨C April News & Updates
panagenda
?
The metaverse : A Digital Transformation
The metaverse : A Digital TransformationThe metaverse : A Digital Transformation
The metaverse : A Digital Transformation
matlotloatang03
?
How Telemedicine App Development is Revolutionizing Virtual Care.pptx
How Telemedicine App Development is Revolutionizing Virtual Care.pptxHow Telemedicine App Development is Revolutionizing Virtual Care.pptx
How Telemedicine App Development is Revolutionizing Virtual Care.pptx
Dash Technologies Inc
?
Artificial Neural Networks, basics, its variations and examples
Artificial Neural Networks, basics, its variations and examplesArtificial Neural Networks, basics, its variations and examples
Artificial Neural Networks, basics, its variations and examples
anandsimple
?

PHPConf-TW 2012 # Twig

  • 2. About Me Wake Liu wake.gs@gmail.com
  • 4. Do I need a template engine?
  • 5. PHP is the most powerful template engine
  • 7. So, we really need a template engine ?
  • 9. Performance ? Compile & cache ? PHP Extension - Twig_Template::getAttribute() ? APC & Memcached
  • 10. How it feels to use Twig
  • 12. Variables ? <?php echo $name; ?> ? {{ name }} ? <?php echo ? {{ member.nickname }} $member->nickname; ?> ? {{ member[¡®nickname¡¯] }} ? <?php ? {{ echo member $member[¡®nickname¡¯]; ? member.nickname ?> : ¡®Guest¡¯ }}
  • 13. Filters / Functions ? <?php echo nl2br ($content); ?> ? <?php echo html_entity_decode ($content); ?> ? <?php echo rand(0, 10); ?> ? {{ content|nl2br }} ? {{ content|raw }} {{ content|nl2br|length }} ? {{ random(10) }}
  • 14. Logic & Loop ? {% if %} {% elseif %} {% else %} {% endif %} ? {% for key, value in data %} {% endfor %} ? {% set name = ¡®wake¡¯ %}
  • 15. Organizational and reusable
  • 16. Extends layout.html <!DOCTYPE html> guest.html <html lang="en"> <head> <meta charset="utf-8"> {% extends layout.html %} <title>The HTML5 Herald</title> </head> <body> {% block wrapper %} default content member.html {% endblock %} {% extends layout.html %} </body> </html>
  • 17. Horizontal reuse page.html navigator.html {% use navigator.html %} {% use login.html %} {% block navigator %} <div class=/slideshow/phpconftw-2012-twig/15031060/¡±wrapper/slideshow/phpconftw-2012-twig/15031060/¡±> <div class=/slideshow/phpconftw-2012-twig/15031060/¡±navigator/slideshow/phpconftw-2012-twig/15031060/¡±> {{ block (¡®navigator¡¯) }} login.html </div> <div class=/slideshow/phpconftw-2012-twig/15031060/¡±login/slideshow/phpconftw-2012-twig/15031060/¡±> {{ block (¡®login¡¯) }} {% block login %} </div> </div>
  • 20. The role of Twig
  • 23. MVC Controller Control ( Logic / Loop ) { C View Data handling ( Filters / Functions ) V View binding ( Structures / Macros ) Model M
  • 24. Hmm, it looks not bad, but ...
  • 27. Photo URL passing photo.html original data <img src=/slideshow/phpconftw-2012-twig/15031060/¡± http://www/:size/photo.jpg {{ url | image_to_large }} /slideshow/phpconftw-2012-twig/15031060/¡±> php de?ne Twig - addFilter _LARGE_PHOTO ¡®L¡¯ _SMALL_PHOTO ¡®S¡¯ image_to_*
  • 28. Template driven member.php A.html class Member { <div> function __get ($name) { {{ member.age }} $loader = ¡°_load$name/slideshow/phpconftw-2012-twig/15031060/¡±; </div> return $this->$loader (); } B.html function _loadAge () { <div> // load from database {{ member.age }} } </div> }

Editor's Notes