0
iGears: Architect Principlesof Template Engines Design
First sight (syntax)Code<?phpif ($items) {foreach ($items as $item) {echo "* {$item}n";}} else {echo "No item has been fou...
First sight (syntax)
First sight (syntax)<title>{% block title %}{% endblock %}</title><ul>{% for user in users %}<li><a href="{{ user.url }}">...
First sight (syntax)FreeMarker<html><body><p>Hello ${name}! You have thefollowing messages:<#list messages as m><p><b>${m....
First sight (syntax)Smarty<ul>{foreach from=$myArray item=foo}<li>{$foo}</li>{/foreach}</ul>
First sight (syntax)XSLT<?xml version="1.0"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"version="1.0"...
First sight (syntax)ERB<div id=content><div class=left column><h2>Welcome to our site!</h2><p><%= print_information %></p>...
Separate logic from viewRoleLogicView
First step — design patterns• MVC• MVP• MVVMApplication architecture
MVCApplication architecture• Input is directed to controller• Many-to-many relationshipbetween View and Controller• View d...
MVPApplication architecture• Input is directed to View• One-to-One relationshipbetween View and Presenter• View holds the ...
MVVMApplication architecture• Input is directed to View• One-to-Many relationshipbetween ViewModel and View• ViewModel hav...
Data presentation in templateFeaturesModel Data Static resources
Data-bindings• Variables from controller• Custom variables• Ierarchy variables (objects, associative arrays)Features – Var...
Format Data (Modificators)• Format numeric data• Date format• Client input filtering• HTML encoding• Static resources form...
Logic implementation• if else operators• inline scripts (ex. {php}{/php})Features – Functions
Loops• For .. in• Loop status (odd, even, count, last, first, index)• Hacker functions (break, continue)Features – Functions
Caching• Cache time• Personalized caching• Partial caching• Application caching• Static caching• Cache controlFeatures - C...
Code Reuse• Includes other templates• Config files usageFeatures – Code Reuse
Points• Platform• Architecture• Data-binding• Functionality• Development resources• Code styleDon’t forget
IGears: Template Architecture and Principles
Upcoming SlideShare
Loading in...5
×

IGears: Template Architecture and Principles

179

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
179
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "IGears: Template Architecture and Principles"

  1. 1. iGears: Architect Principlesof Template Engines Design
  2. 2. First sight (syntax)Code<?phpif ($items) {foreach ($items as $item) {echo "* {$item}n";}} else {echo "No item has been found.n";}?>
  3. 3. First sight (syntax)
  4. 4. First sight (syntax)<title>{% block title %}{% endblock %}</title><ul>{% for user in users %}<li><a href="{{ user.url }}">{{ user.username }}</a></li>{% endfor %}</ul>Jinja
  5. 5. First sight (syntax)FreeMarker<html><body><p>Hello ${name}! You have thefollowing messages:<#list messages as m><p><b>${m.from}:</b>{m.body}</p></#list></body></html>
  6. 6. First sight (syntax)Smarty<ul>{foreach from=$myArray item=foo}<li>{$foo}</li>{/foreach}</ul>
  7. 7. First sight (syntax)XSLT<?xml version="1.0"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"version="1.0"><xsl:template match="/hello-world"><HTML><HEAD><TITLE></TITLE></HEAD><BODY><H1><xsl:value-of select="greeting"/></H1><xsl:apply-templates select="greeter"/></BODY></HTML></xsl:template><xsl:template match="greeter"><DIV>from <I><xsl:value-of select="."/></I></DIV></xsl:template></xsl:stylesheet>
  8. 8. First sight (syntax)ERB<div id=content><div class=left column><h2>Welcome to our site!</h2><p><%= print_information %></p></div><div class="right column"><%= render :partial => "sidebar" %></div></div>#content.left.column%h2 Welcome to our site!%p= print_information.right.column= render :partial => "sidebar"
  9. 9. Separate logic from viewRoleLogicView
  10. 10. First step — design patterns• MVC• MVP• MVVMApplication architecture
  11. 11. MVCApplication architecture• Input is directed to controller• Many-to-many relationshipbetween View and Controller• View doesn’t have anyknowledge about Controller• View is aware of the Model it isexpecting to pass on it
  12. 12. MVPApplication architecture• Input is directed to View• One-to-One relationshipbetween View and Presenter• View holds the reference to it’sPresenter and Presenter is awareof this View• View is not aware of the Model.Presenter updates the Model
  13. 13. MVVMApplication architecture• Input is directed to View• One-to-Many relationshipbetween ViewModel and View• ViewModel haven’t anyknowledge about View• View is not aware of the Model.ViewModel updates the View.
  14. 14. Data presentation in templateFeaturesModel Data Static resources
  15. 15. Data-bindings• Variables from controller• Custom variables• Ierarchy variables (objects, associative arrays)Features – Variables
  16. 16. Format Data (Modificators)• Format numeric data• Date format• Client input filtering• HTML encoding• Static resources formating, placeholdersreplacementsFeatures – Variables
  17. 17. Logic implementation• if else operators• inline scripts (ex. {php}{/php})Features – Functions
  18. 18. Loops• For .. in• Loop status (odd, even, count, last, first, index)• Hacker functions (break, continue)Features – Functions
  19. 19. Caching• Cache time• Personalized caching• Partial caching• Application caching• Static caching• Cache controlFeatures - Cache
  20. 20. Code Reuse• Includes other templates• Config files usageFeatures – Code Reuse
  21. 21. Points• Platform• Architecture• Data-binding• Functionality• Development resources• Code styleDon’t forget
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×