SlideShare a Scribd company logo
1 of 41
Invenzzia Group presentations Open Power Template 2 Open Power Template 2 XML presentation framework / template engine for PHP5
Invenzzia Group presentations Open Power Template 2 Every template engine consists of two parts: - public API: manages the script data and executes templates - template language used to write templates
Invenzzia Group presentations Open Power Template 2 Template engine = Public API + template language Every template engine consists of two parts: - public API that manages the script data and executes templates - template language used to write templates  There are two approaches when choosing a template language: Dedicated template language Template engine introduces a custom language, with simpler syntax, easier to use in HTML templates. Examples: Smarty, Dwoo, PHPTAL PHP as a template language Templates are written in plain PHP supported by extra classes and functions. Examples: Savant, Zend_View
Invenzzia Group presentations Open Power Template 2 Why do people invent new template languages instead of using PHP? Why did they invent PHP instead of writing web applications in C/C++? The answers are simple: Complexity Language limitations Unsuitable syntax
Invenzzia Group presentations Open Power Template 2 PHP drawbacks: ,[object Object]
The code becomes very ugly when we mix it with HTML.
PHP does not understand the HTML document structure.
Lack of useful functions for generating and manipulating HTML code (unless we write it).
Invenzzia Group presentations Open Power Template 2 Template engine = Public API + template language Every template engine consists of two parts: - public API that manages the script data and executes templates - template language used to write templates  A sample list in a PHP template: <?php if(is_array( $items ) && sizeof( $items ) >  0 ){ ?> <div> <h1>Our list</h1> <ol> <?php  $first  = 0; foreach( $items  as  $item ){ ?> <li <?php if( $first  ==  0 ){ echo  ' class=”first”' ; $first  =  1 ; } ?> > <?php echo htmlspecialchars( $item [ 'title' ]); ?> </li> <?php } ?> </ol> </div> <?php } ?> So simple problem and we get a classic example of a write-only code Complex conditions to check if the list is not empty. Hardcoded algorithms to find the first item . Adding new attribute is problematic – PHP does not understand HTML . We must remember to escape the data, and the code becomes longer and longer. And we must know which data are objects and which are arrays.
Invenzzia Group presentations Open Power Template 2 Smarty and many other template engines do not make things better: <?php if(is_array($items) && sizeof($items) > 0){ ?> <div> <h1>Our list</h1> <ol> <?php $first = 0; foreach($items as $item){ ?> <li <?php if($first == 0){ echo ' class=”first”'; $first = 1; } ?> > <?php echo htmlspecialchars($items['title']); ?> </li> <?php } ?> </ol> </div> <?php } ?> An example of a language which repeats the PHP drawbacks and produces new ones.  {if  $items } <div> <h1>Our list</h1> <ol> {assign var= 'first'  value= 0 }{foreach from= $items  item= $item } <li {if  $first  eq  0 }  class=”first” {assign var= 'first'  value= 1 }{/if} > { $item [ title ]|escape} </li> {/foreach} </ol> </div> {/if} We still hard-code every single algorithm in a template: Inventing esoteric syntax for well-known stuff (i.e. function calls). And we still must remember about escaping. Smarty does not understand HTML, too. We must still remember, which item is an array and which is object.
Invenzzia Group presentations Open Power Template 2 Template engine = Public API + template language Every template engine consists of two parts: - public API that manages the script data and executes templates - template language used to write templates  Open Power Template 2 And the solution is... ,[object Object]
Declarative programming – say,  what  you want to have, not  how  it should work.
OPT language is problem-oriented. It focuses on helping with typical templating problems, such as list displaying and HTML form rendering.
Modern, object-oriented and MVC-ready API.
Invenzzia Group presentations Open Power Template 2 OPT facts ,[object Object]
Five-year project history.
Well-documented code and language.
Tested in real world applications, proved its power.
Speeds up template development, increases portability and eases code refactoring.
The development team still identifies new presentation layer problems and develops elegant solutions for them.
OPTv2 is an open-source software.
Invenzzia Group presentations Open Power Template 2 The same problem in OPT: < opt:show   name = ”items” > < div > < h1 > Our list </ h1 > < ol > < li  opt:section = ”items” > < opt:attribute   str:name = ”class”   str:value = ”first” opt:if =” $system.section.items.first ”  /> { $items.title } </ li > </ ol > </ div > </ opt:show > Sections, smart loops, hide all the logic and data type-specific issues. The parser understands HTML and makes use of it. We do not have to find our way to determine the first element in a list. In declarative programming, OPT does it for us. The data are automatically escaped. And we do not even have to know, if this is an object or array.
Invenzzia Group presentations Open Power Template 2 <opt:show name=”items”> <div> <h1>Our list</h1> <ol> <li  opt:section=”items” > <opt:attribute str:name=”class” str:value=”first” opt:if=”$system.section.items.first”> {$items.title} </li> </ol> </div> </opt:show> Thanks to the XML parser, OPT reports all the HTML syntax errors for you, just like the validator, but for  all  your templates and  constantly . < opt:show   name = ”items” > < div > < h1 > Our list </p> < ol > < li  opt:section = ”items” > < opt:attribute   str:name = ”class”   str:value = ”first” opt:if =” $system.section.items.first ”  /> { $items.title } </ li > </ ol > ??? </ opt:show >
Invenzzia Group presentations Open Power Template 2 Open Power Template 2 A short trip over the template language features
Invenzzia Group presentations Open Power Template 2 Sections ,[object Object]
Four types of sections: traditional lists, selectors, trees and grids.
Very simple process of creating nested sections and relationships between them.
Declarative design – focus on how the list should look like, not – how it should work.
The iteration details can be changed from the script level without rewriting templates.
Invenzzia Group presentations Open Power Template 2 < opt:section name = ”entries” > < div class= ”entry” > < h1 > { $entries.title } </ h1 > { u : $entries.body }   <!-- do not escape the body --> < span class= ”tags” > < opt:section name = ”tags”   str:separator = ”, ” > < a  parse:href =” url( '/show/tag?tag=' ~ $tags.slug ) ” > { $tags.title } </ a > </ opt:section > </ span > </ div > </ opt:section > < div id= ”pagination” > < opt:selector name = ”paginator” > < opt:page > < a  parse:href =” $paginator.url ” > { $paginator.number } </ a ></ opt:page > < opt:active >< span class= ”active” > { $paginator.number } </ span ></ opt:active > < opt:gap > ... </ opt:gap > </ opt:selector > </ div > The main template of a blog created with OPT sections.
Invenzzia Group presentations Open Power Template 2 Template inheritance ,[object Object]
For the first time introduced in Python template engines.
Similar to object-oriented programming.
Instead of classes, we extend templates.
Instead of methods, we have snippets.
Invenzzia Group presentations Open Power Template 2 Template inheritance – base template We leave placeholders for the extending templates. <?xml version=”1.0” ?> < opt:root > < html > < head > < title >< opt:insert snippet = ”title”   /></ title > </ head > < body > < div id= ”header” >< opt:insert snippet = ”header” > < h1 > My website </ h1 >   <!-- the default content --> </ opt:insert ></ div> < div id= ”content” > < opt:insert snippet = ”content”   /> </ div > </ body > </ html > </ opt:root >
Invenzzia Group presentations Open Power Template 2 Template inheritance – base template We leave placeholders for the extending templates. <?xml version=”1.0” ?> <opt:root> <html> <head> <title> <opt:insert snippet=”title” /> </title> </head> <body> <div id=”header”> <opt:insert snippet=”header”> <h1>My website</h1> <!-- the default content --> </opt:insert> </div> <div id=”content”> <opt:insert snippet=”content” /> </div> </body> </html> </opt:root> <?xml version=”1.0” ?> < opt:extend file = ”base.tpl” > < opt:snippet name = ”title” > My title </ opt:snippet > < opt:snippet name = ”header” > < opt:parent   />< h2 > Home page </ h2 > </ opt:snippet > < opt:snippet name = ”content” > < p > Some content goes here </ p > </ opt:snippet > </ opt:root > Template inheritance – extending template. We specify the content for the placeholders, using snippets. Note that the default content may be used in our work thanks to  <opt:parent/>
Invenzzia Group presentations Open Power Template 2 The form processing problem How to keep the form definition and validation rules in one place? How not to move the form look&feel issues to the presentation logic or the controller? How to keep the look&feel code compact and reusable according to DRY rules? How to keep the freedom of editing pure, custom HTML for certain form elements?
Invenzzia Group presentations Open Power Template 2 PHP-based systems simply  do not work  here!   Zend Framework : form look&feel configured by massive OOP manipulations, often in the controller layer. The simplest custom change of HTML code must be hardcoded as another set of PHP classes. Kohana Framework : provides only the simplest helpers. Binding them with the form status, error reporting, look&feel issues must be hardcoded in PHP for each single field of each form (unless we write a new PHP layer over it). Symfony Framework : form library independent from the template engine – repeats part of its functionality. We can either hard-code everything, like in Kohana, or reconfigure dozens of default  template templates  written in PHP.
Invenzzia Group presentations Open Power Template 2 OPT Components ,[object Object]
Separate form field logic (managed by user-defined PHP classes) from their presentation (managed by templates).

More Related Content

What's hot

ImplementingChangeTrackingAndFlagging
ImplementingChangeTrackingAndFlaggingImplementingChangeTrackingAndFlagging
ImplementingChangeTrackingAndFlaggingSuite Solutions
 
C:\Users\User\Desktop\Eclipse Infocenter
C:\Users\User\Desktop\Eclipse InfocenterC:\Users\User\Desktop\Eclipse Infocenter
C:\Users\User\Desktop\Eclipse InfocenterSuite Solutions
 
Developing and testing ajax components
Developing and testing ajax componentsDeveloping and testing ajax components
Developing and testing ajax componentsIgnacio Coloma
 
Inroduction to XSLT with PHP4
Inroduction to XSLT with PHP4Inroduction to XSLT with PHP4
Inroduction to XSLT with PHP4Stephan Schmidt
 
Demystifying Keyword Driven Using Watir
Demystifying Keyword Driven Using WatirDemystifying Keyword Driven Using Watir
Demystifying Keyword Driven Using WatirHirday Lamba
 
P H P Part I I, By Kian
P H P  Part  I I,  By  KianP H P  Part  I I,  By  Kian
P H P Part I I, By Kianphelios
 
Component and Event-Driven Architectures in PHP
Component and Event-Driven Architectures in PHPComponent and Event-Driven Architectures in PHP
Component and Event-Driven Architectures in PHPStephan Schmidt
 
XML and Web Services with PHP5 and PEAR
XML and Web Services with PHP5 and PEARXML and Web Services with PHP5 and PEAR
XML and Web Services with PHP5 and PEARStephan Schmidt
 
Web REST APIs Design Principles
Web REST APIs Design PrinciplesWeb REST APIs Design Principles
Web REST APIs Design PrinciplesAnji Beeravalli
 
Make Your Own Damn SEO Tools (Using Google Docs!)
Make Your Own Damn SEO Tools (Using Google Docs!)Make Your Own Damn SEO Tools (Using Google Docs!)
Make Your Own Damn SEO Tools (Using Google Docs!)Sean Malseed
 
Coder Presentation
Coder  PresentationCoder  Presentation
Coder PresentationDoug Green
 
Article 01 What Is Php
Article 01   What Is PhpArticle 01   What Is Php
Article 01 What Is Phpdrperl
 
Intro to html5 Boilerplate
Intro to html5 BoilerplateIntro to html5 Boilerplate
Intro to html5 BoilerplateMichael Enslow
 
Facebook Development with Zend Framework
Facebook Development with Zend FrameworkFacebook Development with Zend Framework
Facebook Development with Zend FrameworkBrett Harris
 

What's hot (20)

ImplementingChangeTrackingAndFlagging
ImplementingChangeTrackingAndFlaggingImplementingChangeTrackingAndFlagging
ImplementingChangeTrackingAndFlagging
 
Ot performance webinar
Ot performance webinarOt performance webinar
Ot performance webinar
 
C:\Users\User\Desktop\Eclipse Infocenter
C:\Users\User\Desktop\Eclipse InfocenterC:\Users\User\Desktop\Eclipse Infocenter
C:\Users\User\Desktop\Eclipse Infocenter
 
PDF Localization
PDF  LocalizationPDF  Localization
PDF Localization
 
Developing and testing ajax components
Developing and testing ajax componentsDeveloping and testing ajax components
Developing and testing ajax components
 
Inroduction to XSLT with PHP4
Inroduction to XSLT with PHP4Inroduction to XSLT with PHP4
Inroduction to XSLT with PHP4
 
Dost.jar and fo.jar
Dost.jar and fo.jarDost.jar and fo.jar
Dost.jar and fo.jar
 
Demystifying Keyword Driven Using Watir
Demystifying Keyword Driven Using WatirDemystifying Keyword Driven Using Watir
Demystifying Keyword Driven Using Watir
 
P H P Part I I, By Kian
P H P  Part  I I,  By  KianP H P  Part  I I,  By  Kian
P H P Part I I, By Kian
 
Component and Event-Driven Architectures in PHP
Component and Event-Driven Architectures in PHPComponent and Event-Driven Architectures in PHP
Component and Event-Driven Architectures in PHP
 
displaytag
displaytagdisplaytag
displaytag
 
XML and Web Services with PHP5 and PEAR
XML and Web Services with PHP5 and PEARXML and Web Services with PHP5 and PEAR
XML and Web Services with PHP5 and PEAR
 
Php
PhpPhp
Php
 
Web REST APIs Design Principles
Web REST APIs Design PrinciplesWeb REST APIs Design Principles
Web REST APIs Design Principles
 
Make Your Own Damn SEO Tools (Using Google Docs!)
Make Your Own Damn SEO Tools (Using Google Docs!)Make Your Own Damn SEO Tools (Using Google Docs!)
Make Your Own Damn SEO Tools (Using Google Docs!)
 
Apache Persistence Layers
Apache Persistence LayersApache Persistence Layers
Apache Persistence Layers
 
Coder Presentation
Coder  PresentationCoder  Presentation
Coder Presentation
 
Article 01 What Is Php
Article 01   What Is PhpArticle 01   What Is Php
Article 01 What Is Php
 
Intro to html5 Boilerplate
Intro to html5 BoilerplateIntro to html5 Boilerplate
Intro to html5 Boilerplate
 
Facebook Development with Zend Framework
Facebook Development with Zend FrameworkFacebook Development with Zend Framework
Facebook Development with Zend Framework
 

Viewers also liked (15)

Xml
XmlXml
Xml
 
What is xml
What is xmlWhat is xml
What is xml
 
XML Training Presentation
XML Training PresentationXML Training Presentation
XML Training Presentation
 
Xml
XmlXml
Xml
 
Xml intro1
Xml intro1Xml intro1
Xml intro1
 
XML and Databases
XML and DatabasesXML and Databases
XML and Databases
 
Intro to JSON
Intro to JSONIntro to JSON
Intro to JSON
 
XML 101 presentation by Bill Kasdorf of Apex
XML 101 presentation by Bill Kasdorf of ApexXML 101 presentation by Bill Kasdorf of Apex
XML 101 presentation by Bill Kasdorf of Apex
 
Xml Presentation-1
Xml Presentation-1Xml Presentation-1
Xml Presentation-1
 
Functions using stack and heap
Functions using stack and heapFunctions using stack and heap
Functions using stack and heap
 
Xml Presentation-3
Xml Presentation-3Xml Presentation-3
Xml Presentation-3
 
XML Databases
XML DatabasesXML Databases
XML Databases
 
XML for beginners
XML for beginnersXML for beginners
XML for beginners
 
Xml ppt
Xml pptXml ppt
Xml ppt
 
Introduction à XML
Introduction à XMLIntroduction à XML
Introduction à XML
 

Similar to Open Power Template 2 presentation

Drupal 7 Theming - what's new
Drupal 7 Theming - what's newDrupal 7 Theming - what's new
Drupal 7 Theming - what's newMarek Sotak
 
WordPress Standardized Loop API
WordPress Standardized Loop APIWordPress Standardized Loop API
WordPress Standardized Loop APIChris Jean
 
Система рендеринга в Magento
Система рендеринга в MagentoСистема рендеринга в Magento
Система рендеринга в MagentoMagecom Ukraine
 
Open Source Package PHP & MySQL
Open Source Package PHP & MySQLOpen Source Package PHP & MySQL
Open Source Package PHP & MySQLkalaisai
 
Introduction To Lamp
Introduction To LampIntroduction To Lamp
Introduction To LampAmzad Hossain
 
PHPTAL introduction
PHPTAL introductionPHPTAL introduction
PHPTAL introduction'"">
 
Developing Gadgets
Developing GadgetsDeveloping Gadgets
Developing GadgetsQuirk
 
course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpointwebhostingguy
 
Dynamic Web Pages Ch 1 V1.0
Dynamic Web Pages Ch 1 V1.0Dynamic Web Pages Ch 1 V1.0
Dynamic Web Pages Ch 1 V1.0Cathie101
 
Various Ways of Using WordPress
Various Ways of Using WordPressVarious Ways of Using WordPress
Various Ways of Using WordPressNick La
 
Smarter Interfaces with jQuery (and Drupal)
Smarter Interfaces with jQuery (and Drupal)Smarter Interfaces with jQuery (and Drupal)
Smarter Interfaces with jQuery (and Drupal)aasarava
 
Enterprise Google Gadgets Integrated with Alfresco - Open Source ECM
Enterprise Google Gadgets Integrated with Alfresco - Open Source ECM Enterprise Google Gadgets Integrated with Alfresco - Open Source ECM
Enterprise Google Gadgets Integrated with Alfresco - Open Source ECM Alfresco Software
 
Introduction to Elgg
Introduction to ElggIntroduction to Elgg
Introduction to Elggniteshnandy
 

Similar to Open Power Template 2 presentation (20)

Drupal 7 Theming - what's new
Drupal 7 Theming - what's newDrupal 7 Theming - what's new
Drupal 7 Theming - what's new
 
WordPress Standardized Loop API
WordPress Standardized Loop APIWordPress Standardized Loop API
WordPress Standardized Loop API
 
Система рендеринга в Magento
Система рендеринга в MagentoСистема рендеринга в Magento
Система рендеринга в Magento
 
Open Source Package PHP & MySQL
Open Source Package PHP & MySQLOpen Source Package PHP & MySQL
Open Source Package PHP & MySQL
 
Introduction To Lamp
Introduction To LampIntroduction To Lamp
Introduction To Lamp
 
PHPTAL introduction
PHPTAL introductionPHPTAL introduction
PHPTAL introduction
 
Developing Gadgets
Developing GadgetsDeveloping Gadgets
Developing Gadgets
 
course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpoint
 
Control Structures In Php 2
Control Structures In Php 2Control Structures In Php 2
Control Structures In Php 2
 
Dynamic Web Pages Ch 1 V1.0
Dynamic Web Pages Ch 1 V1.0Dynamic Web Pages Ch 1 V1.0
Dynamic Web Pages Ch 1 V1.0
 
Struts2
Struts2Struts2
Struts2
 
Html5 Overview
Html5 OverviewHtml5 Overview
Html5 Overview
 
Various Ways of Using WordPress
Various Ways of Using WordPressVarious Ways of Using WordPress
Various Ways of Using WordPress
 
Smarter Interfaces with jQuery (and Drupal)
Smarter Interfaces with jQuery (and Drupal)Smarter Interfaces with jQuery (and Drupal)
Smarter Interfaces with jQuery (and Drupal)
 
Ajax ons2
Ajax ons2Ajax ons2
Ajax ons2
 
Tugas Pw [6]
Tugas Pw [6]Tugas Pw [6]
Tugas Pw [6]
 
Tugas Pw [6] (2)
Tugas Pw [6] (2)Tugas Pw [6] (2)
Tugas Pw [6] (2)
 
Enterprise Google Gadgets Integrated with Alfresco - Open Source ECM
Enterprise Google Gadgets Integrated with Alfresco - Open Source ECM Enterprise Google Gadgets Integrated with Alfresco - Open Source ECM
Enterprise Google Gadgets Integrated with Alfresco - Open Source ECM
 
Web Designing
Web DesigningWeb Designing
Web Designing
 
Introduction to Elgg
Introduction to ElggIntroduction to Elgg
Introduction to Elgg
 

Recently uploaded

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
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
#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
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 

Recently uploaded (20)

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
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
#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
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 

Open Power Template 2 presentation

  • 1. Invenzzia Group presentations Open Power Template 2 Open Power Template 2 XML presentation framework / template engine for PHP5
  • 2. Invenzzia Group presentations Open Power Template 2 Every template engine consists of two parts: - public API: manages the script data and executes templates - template language used to write templates
  • 3. Invenzzia Group presentations Open Power Template 2 Template engine = Public API + template language Every template engine consists of two parts: - public API that manages the script data and executes templates - template language used to write templates There are two approaches when choosing a template language: Dedicated template language Template engine introduces a custom language, with simpler syntax, easier to use in HTML templates. Examples: Smarty, Dwoo, PHPTAL PHP as a template language Templates are written in plain PHP supported by extra classes and functions. Examples: Savant, Zend_View
  • 4. Invenzzia Group presentations Open Power Template 2 Why do people invent new template languages instead of using PHP? Why did they invent PHP instead of writing web applications in C/C++? The answers are simple: Complexity Language limitations Unsuitable syntax
  • 5.
  • 6. The code becomes very ugly when we mix it with HTML.
  • 7. PHP does not understand the HTML document structure.
  • 8. Lack of useful functions for generating and manipulating HTML code (unless we write it).
  • 9. Invenzzia Group presentations Open Power Template 2 Template engine = Public API + template language Every template engine consists of two parts: - public API that manages the script data and executes templates - template language used to write templates A sample list in a PHP template: <?php if(is_array( $items ) && sizeof( $items ) > 0 ){ ?> <div> <h1>Our list</h1> <ol> <?php $first = 0; foreach( $items as $item ){ ?> <li <?php if( $first == 0 ){ echo ' class=”first”' ; $first = 1 ; } ?> > <?php echo htmlspecialchars( $item [ 'title' ]); ?> </li> <?php } ?> </ol> </div> <?php } ?> So simple problem and we get a classic example of a write-only code Complex conditions to check if the list is not empty. Hardcoded algorithms to find the first item . Adding new attribute is problematic – PHP does not understand HTML . We must remember to escape the data, and the code becomes longer and longer. And we must know which data are objects and which are arrays.
  • 10. Invenzzia Group presentations Open Power Template 2 Smarty and many other template engines do not make things better: <?php if(is_array($items) && sizeof($items) > 0){ ?> <div> <h1>Our list</h1> <ol> <?php $first = 0; foreach($items as $item){ ?> <li <?php if($first == 0){ echo ' class=”first”'; $first = 1; } ?> > <?php echo htmlspecialchars($items['title']); ?> </li> <?php } ?> </ol> </div> <?php } ?> An example of a language which repeats the PHP drawbacks and produces new ones. {if $items } <div> <h1>Our list</h1> <ol> {assign var= 'first' value= 0 }{foreach from= $items item= $item } <li {if $first eq 0 } class=”first” {assign var= 'first' value= 1 }{/if} > { $item [ title ]|escape} </li> {/foreach} </ol> </div> {/if} We still hard-code every single algorithm in a template: Inventing esoteric syntax for well-known stuff (i.e. function calls). And we still must remember about escaping. Smarty does not understand HTML, too. We must still remember, which item is an array and which is object.
  • 11.
  • 12. Declarative programming – say, what you want to have, not how it should work.
  • 13. OPT language is problem-oriented. It focuses on helping with typical templating problems, such as list displaying and HTML form rendering.
  • 14. Modern, object-oriented and MVC-ready API.
  • 15.
  • 18. Tested in real world applications, proved its power.
  • 19. Speeds up template development, increases portability and eases code refactoring.
  • 20. The development team still identifies new presentation layer problems and develops elegant solutions for them.
  • 21. OPTv2 is an open-source software.
  • 22. Invenzzia Group presentations Open Power Template 2 The same problem in OPT: < opt:show name = ”items” > < div > < h1 > Our list </ h1 > < ol > < li opt:section = ”items” > < opt:attribute str:name = ”class” str:value = ”first” opt:if =” $system.section.items.first ” /> { $items.title } </ li > </ ol > </ div > </ opt:show > Sections, smart loops, hide all the logic and data type-specific issues. The parser understands HTML and makes use of it. We do not have to find our way to determine the first element in a list. In declarative programming, OPT does it for us. The data are automatically escaped. And we do not even have to know, if this is an object or array.
  • 23. Invenzzia Group presentations Open Power Template 2 <opt:show name=”items”> <div> <h1>Our list</h1> <ol> <li opt:section=”items” > <opt:attribute str:name=”class” str:value=”first” opt:if=”$system.section.items.first”> {$items.title} </li> </ol> </div> </opt:show> Thanks to the XML parser, OPT reports all the HTML syntax errors for you, just like the validator, but for all your templates and constantly . < opt:show name = ”items” > < div > < h1 > Our list </p> < ol > < li opt:section = ”items” > < opt:attribute str:name = ”class” str:value = ”first” opt:if =” $system.section.items.first ” /> { $items.title } </ li > </ ol > ??? </ opt:show >
  • 24. Invenzzia Group presentations Open Power Template 2 Open Power Template 2 A short trip over the template language features
  • 25.
  • 26. Four types of sections: traditional lists, selectors, trees and grids.
  • 27. Very simple process of creating nested sections and relationships between them.
  • 28. Declarative design – focus on how the list should look like, not – how it should work.
  • 29. The iteration details can be changed from the script level without rewriting templates.
  • 30. Invenzzia Group presentations Open Power Template 2 < opt:section name = ”entries” > < div class= ”entry” > < h1 > { $entries.title } </ h1 > { u : $entries.body } <!-- do not escape the body --> < span class= ”tags” > < opt:section name = ”tags” str:separator = ”, ” > < a parse:href =” url( '/show/tag?tag=' ~ $tags.slug ) ” > { $tags.title } </ a > </ opt:section > </ span > </ div > </ opt:section > < div id= ”pagination” > < opt:selector name = ”paginator” > < opt:page > < a parse:href =” $paginator.url ” > { $paginator.number } </ a ></ opt:page > < opt:active >< span class= ”active” > { $paginator.number } </ span ></ opt:active > < opt:gap > ... </ opt:gap > </ opt:selector > </ div > The main template of a blog created with OPT sections.
  • 31.
  • 32. For the first time introduced in Python template engines.
  • 34. Instead of classes, we extend templates.
  • 35. Instead of methods, we have snippets.
  • 36. Invenzzia Group presentations Open Power Template 2 Template inheritance – base template We leave placeholders for the extending templates. <?xml version=”1.0” ?> < opt:root > < html > < head > < title >< opt:insert snippet = ”title” /></ title > </ head > < body > < div id= ”header” >< opt:insert snippet = ”header” > < h1 > My website </ h1 > <!-- the default content --> </ opt:insert ></ div> < div id= ”content” > < opt:insert snippet = ”content” /> </ div > </ body > </ html > </ opt:root >
  • 37. Invenzzia Group presentations Open Power Template 2 Template inheritance – base template We leave placeholders for the extending templates. <?xml version=”1.0” ?> <opt:root> <html> <head> <title> <opt:insert snippet=”title” /> </title> </head> <body> <div id=”header”> <opt:insert snippet=”header”> <h1>My website</h1> <!-- the default content --> </opt:insert> </div> <div id=”content”> <opt:insert snippet=”content” /> </div> </body> </html> </opt:root> <?xml version=”1.0” ?> < opt:extend file = ”base.tpl” > < opt:snippet name = ”title” > My title </ opt:snippet > < opt:snippet name = ”header” > < opt:parent />< h2 > Home page </ h2 > </ opt:snippet > < opt:snippet name = ”content” > < p > Some content goes here </ p > </ opt:snippet > </ opt:root > Template inheritance – extending template. We specify the content for the placeholders, using snippets. Note that the default content may be used in our work thanks to <opt:parent/>
  • 38. Invenzzia Group presentations Open Power Template 2 The form processing problem How to keep the form definition and validation rules in one place? How not to move the form look&feel issues to the presentation logic or the controller? How to keep the look&feel code compact and reusable according to DRY rules? How to keep the freedom of editing pure, custom HTML for certain form elements?
  • 39. Invenzzia Group presentations Open Power Template 2 PHP-based systems simply do not work here! Zend Framework : form look&feel configured by massive OOP manipulations, often in the controller layer. The simplest custom change of HTML code must be hardcoded as another set of PHP classes. Kohana Framework : provides only the simplest helpers. Binding them with the form status, error reporting, look&feel issues must be hardcoded in PHP for each single field of each form (unless we write a new PHP layer over it). Symfony Framework : form library independent from the template engine – repeats part of its functionality. We can either hard-code everything, like in Kohana, or reconfigure dozens of default template templates written in PHP.
  • 40.
  • 41. Separate form field logic (managed by user-defined PHP classes) from their presentation (managed by templates).
  • 42. PHP form processing engine is separated from the presentation issues.
  • 43. Rich interface with a number of useful features.
  • 44. You can create form fields explicitely or load their objects from the script.
  • 45.
  • 46. Generate the widget HTML code only, such as <input type=”text” />
  • 47. Possess flexible interface to communicate with the template with events or parameters.
  • 48. Manage the component logic – they can communicate with the form processing engine, downloading the information about validation errors or element status.
  • 49.
  • 50. Define the layout of the entire element, including the labels, places for error messages, and for rendering the widget itself.
  • 51. May load the component objects from the script or create them on their own.
  • 52. The layout can be saved in snippets (the same, as in the template inheritance) and reused over all the forms.
  • 53. Invenzzia Group presentations Open Power Template 2 Sample form – part 1 <!-- static deployment, loading the l&f from a snippet --> < form:input name = ”title” template = ”standardLayout” > < opt:set str:name = ”label” str:value = ”Title” /> </ form:input > <!-- custom layout --> < form:input name = ”age” label = ”Age” > < div opt:component-attributes = ”default” > < label parse:for =” $system.component.id ” > { $system.component.label } </ label > < opt:display /> < opt:onEvent name = ”error” > < p class= ”error” > { $system.component.errorMessage } </ p > </ opt:onEvent > </ div > </ form:input >
  • 54. Invenzzia Group presentations Open Power Template 2 Sample form – part 2 <!-- static deployment, loading the l&f from a snippet --> <form:input name=”title” template=”standardLayout”> <opt:set str:name=”label” str:value=”Title” /> </form:input> <!-- custom layout --> <form:input name=”age” label=”Age”> <div opt:component-attributes=”default”> <label parse:for=”$system.component.id”>{$system.component.label} </label> <opt:display /> <opt:onEvent name=”error”> <p class=”error”>{$system.component.errorMessage}</p> </opt:onEvent> </div> </form> <!-- dynamic deployment: load everything from a section --> < o pt:section name = ”widgets” > < opt:component from =” $widgets.component ” template = ”standardLayout” > <!-- we can still set some extra component parameters --> < opt:set str:name = ”specificParam” str:value = ”Foo” /> </ opt:component > </ opt:section >
  • 55. Invenzzia Group presentations Open Power Template 2 Open Power Template does not provide a form processing engine. Open Power Template does provide a framework to render the forms in templates which must be extended by a form processing library. Open Power Forms – a project of the form processing library integrated with OPT. Currently under active development.
  • 56.
  • 57. Optimizes the PHP expression syntax for XML language in order to avoid using entities.
  • 58. Full syntax validation and error reporting provided.
  • 59.
  • 60. Smarty: $variable1 | modifier : $variable2
  • 61. Invenzzia Group presentations Open Power Template 2 Expression engine: examples <!-- display a variable value in a text --> < p > some text { $variable } some text </ p > <!-- an expression generating the CSS class name in the attribute --> < span parse:class =” 'error ' ~ $customCss ” > ... </ span > <!-- formatting a text --> < p > {capitalize ( $text ) } </ p > <!-- complex mathematical calculations --> < p > { $a + $b * ( $c – 17.43 ) } </ p > <!-- variable assignments --> { $foo is 'bar' } , { $bar = 'joe' } <!-- translation support --> < p > { $news@pageTitle } </ p >
  • 62. Invenzzia Group presentations Open Power Template 2 Expression engine: containers An abstraction built over compound PHP data types: arrays and objects < h1 > { $article.title } </ h1 > < p > { $article.body } </ p > You do not have to know the exact data types returned by your models while you are writing a template. You can copy and reuse the same templates and template parts in different places without the need to rewrite them to the new context. OPT does it for you, using the configuration from a script. < title > { $helpers.title.getTitle } </ title > Containers can represent even more complex structures, such as view helpers, hiding their real nature and providing the unified access to them and their properties.
  • 63.
  • 64. Hides the real nature of the displayed data, which allows you to write the templates independently from the model layer implementation details.
  • 65. Brings KISS and DRY rules to the template engine world.
  • 66. Frees you from reinventing the wheel over and over again.
  • 68. Invenzzia Group presentations Open Power Template 2 Open Power Template 2 Library API
  • 69. Invenzzia Group presentations Open Power Template 2 Most available template engines are object-oriented only by the name. Usually, their end-user API is reduced to a „class-for-everything”: Smarty, Dwoo, Savant, PHPTAL, PHP-Sugar, and many more... They may reinvent some of the PHP stuff: Smarty and resources vs PHP streams Or simply provide lots of „extra” features that should not be a concern of template engines: Smarty and caching
  • 70. Invenzzia Group presentations Open Power Template 2 This does not happen in OPT 2! Usually, their end-user API is reduced to a „class-for-everything”: Smarty, Dwoo, Savant, PHPTAL, PHP-Sugar, and many more... They may reinvent some of the PHP stuff: Smarty and resources vs PHP streams Or simply provide lots of „extra” features that should not be a concern of template engines: Smarty and caching
  • 71. Invenzzia Group presentations Open Power Template 2 Open Power Template architecture
  • 72.
  • 73. Opt_View objects – represent the templates with their data. Each view has a custom variable scope.
  • 74. Opt_Output_Interface – send the result of a template execution (ready XML document) to the destination place.
  • 75. Template compiler – compiles the XML templates to a easy-to-execute, fast and compact PHP code.
  • 76. Runtime functions – provide different runtime features for executed templates.
  • 77. Invenzzia Group presentations Open Power Template 2 Sample code Opl_Loader :: setDirectory ( './libs/Opl' ) ; Opl_Loader :: register () ; try { $opt = new Opt_Class ; $opt->sourceDir = './templates/' ; $opt->compileDir = './templates_c/' ; $opt->setup(); $view = new Opt_View ( 'template.tpl' ) ; $view->var1 = 'Foo' ; $view->var2 = array ( 'foo' => 'abc' , 'bar' => 'def' ) ; $view->var3 = new MyObject ; $view->setFormat ( 'var3' , 'Objective' ) ; $output = new Opt_Output_Http ; $output->setContentType ( Opt_Output_Http ::XHTML, 'utf-8' ) ; $output->render ( $view ) ; } catch ( Opt_Exception $exception ) ...
  • 78. Invenzzia Group presentations Open Power Template 2 Performance Of course, we do remember about it. And you will be surprised by the results...
  • 79. Invenzzia Group presentations Open Power Template 2 Performance OPT is a bit slower for the smallest and the simplest templates ran once, where the library loading plays the most important role. OPT becomes faster if we start writing bigger and more complex templates, and such templates usually are used on most websites. OPT is faster than Smarty and even than pure PHP in Zend_View in more complex benchmark tests.
  • 80. Invenzzia Group presentations Open Power Template 2 Performance facts OPT execution algorithm is very simple and well-optimized. Most of the library is not even loaded, if we do not compile the templates. The template compiler is not limited by the readability of the output PHP code. Thus, it can generate more optimized code than human-made PHP templates, the best for the concrete situation. The template compiler can solve many problems during the compilation, which is done only when the template source changes. At the same time, PHP templates must execute the same fundamental code on runtime. New versions may introduce new optimizations that are automatically applied to your templates after recompilation.
  • 81. Invenzzia Group presentations Open Power Template 2 Open Power Template 2 Tools, extensions, ports
  • 82. Invenzzia Group presentations Open Power Template 2 OPT is the first step towards constructing a complete, new generation presentation layer solution for frameworks and PHP web applications. Open Power Forms – form processing library integrated with OPT. Currently under active development. Open Power Classes – set of smaller OPT-ready utility classes. Under active development. Zend Framework port – the advanced port that makes the integration with ZF easy.
  • 83. Invenzzia Group presentations Open Power Template 2 Template engine = Public API + template language Every template engine consists of two parts: - public API that manages the script data and executes templates - template language used to write templates Got interested? Visit www.invenzzia.org and discover the power of Open Power Template 2 yourself! © by Invenzzia Group 2009 - www.invenzzia.org