SlideShare a Scribd company logo
Template Toolkit
Templating ,[object Object]
Feed document through program
Output is as you wanted
Fantastic! People started writing their own templating systems, because it increased productivity. ,[object Object]
Formalized Templating Systems ,[object Object]
Portability
Trainability
More extensive features
Get someone else to manage the templates  ,[object Object]
Other Templating Systems ,[object Object]
HTML::Template
HTML::Mason
HTML::Embperl
Apache::ASP
Template Toolkit ,[object Object]
Usable through a number of web frameworks
Documented on the web ,[object Object],[object Object],[object Object],[object Object]
Installing Template Toolkit ,[object Object]
cpan>install Template
#cpan Template ,[object Object]
Installed as part of the standard Catalyst installation.
Using Template Toolkit #! /usr/bin/perl use strict; use Template; my $tt = Template->new(); my $file = “webpage.tt”; my $vars = { person => 'Sam Spade',  book => 'Maltese Falcon' }; $tt->process( $file, $vars ) || die $tt->error();
Passing Variables to TT Hashes and arrays should be passed as references: $arrayref = [ 1, 2, 3, 4 ]; $hashref = { foo => 1, bar => 2 }; This is also true within Catalyst
Simple example template Dear [%- customer -%], We are introducing five new products we want you to consider: [% product.0 %] [% product.1 %] [% product.2 %] [% product.3 %] [% product.4 %]
Pre and post chomp No chomp [% foo %] Pre chomp – removes  before current line [%- foo %] Post chomp – removes  on current line [% foo -%] Both pre and post chomped [%- foo -%] ^_^
Dots dereference components. [% myhash.3.component.7.subcomponent %]
TT provides virtual methods.  In use, looks like Ruby [% string.length %] [% myhash.keys.sort %] [% hashlist.keys.sort.join(', ') %]
TT flow of control These teams have the following quarterbacks: [% FOREACH team IN league.keys.sort -%] [% NEXT UNLESS team.defined -%] [% team.name %]: [% team.qb %] [% IF team.owner -%] This team is owned by [% team.owner -%] [% ELSE -%] This team is owned by a committee. [% END -%] [% END -%]
Flow of control Part II ,[object Object]
WHILE
NEXT, LAST

More Related Content

What's hot

Installing php 7.4 Nginx Laravel 7.x on Centos 8
Installing php 7.4 Nginx Laravel 7.x on Centos 8Installing php 7.4 Nginx Laravel 7.x on Centos 8
Installing php 7.4 Nginx Laravel 7.x on Centos 8
Raja Rozali Raja Hasan
 
Kyiv.py #17 Flask talk
Kyiv.py #17 Flask talkKyiv.py #17 Flask talk
Kyiv.py #17 Flask talk
Alexey Popravka
 
Rails Plugin Development 101 (...and some...)
Rails Plugin Development 101 (...and some...)Rails Plugin Development 101 (...and some...)
Rails Plugin Development 101 (...and some...)
Jim Myhrberg
 
Flask patterns
Flask patternsFlask patterns
Flask patterns
it-people
 
The Django Book / Chapter 3: Views and URLconfs
The Django Book / Chapter 3: Views and URLconfsThe Django Book / Chapter 3: Views and URLconfs
The Django Book / Chapter 3: Views and URLconfs
Vincent Chien
 
Workshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - phpbelfastWorkshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - phpbelfast
Michelangelo van Dam
 
It kpi maillist template engine
It kpi maillist template engineIt kpi maillist template engine
It kpi maillist template engine
Roman Rader
 
Basic commands for powershell : Configuring Windows PowerShell and working wi...
Basic commands for powershell : Configuring Windows PowerShell and working wi...Basic commands for powershell : Configuring Windows PowerShell and working wi...
Basic commands for powershell : Configuring Windows PowerShell and working wi...
Hitesh Mohapatra
 

What's hot (8)

Installing php 7.4 Nginx Laravel 7.x on Centos 8
Installing php 7.4 Nginx Laravel 7.x on Centos 8Installing php 7.4 Nginx Laravel 7.x on Centos 8
Installing php 7.4 Nginx Laravel 7.x on Centos 8
 
Kyiv.py #17 Flask talk
Kyiv.py #17 Flask talkKyiv.py #17 Flask talk
Kyiv.py #17 Flask talk
 
Rails Plugin Development 101 (...and some...)
Rails Plugin Development 101 (...and some...)Rails Plugin Development 101 (...and some...)
Rails Plugin Development 101 (...and some...)
 
Flask patterns
Flask patternsFlask patterns
Flask patterns
 
The Django Book / Chapter 3: Views and URLconfs
The Django Book / Chapter 3: Views and URLconfsThe Django Book / Chapter 3: Views and URLconfs
The Django Book / Chapter 3: Views and URLconfs
 
Workshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - phpbelfastWorkshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - phpbelfast
 
It kpi maillist template engine
It kpi maillist template engineIt kpi maillist template engine
It kpi maillist template engine
 
Basic commands for powershell : Configuring Windows PowerShell and working wi...
Basic commands for powershell : Configuring Windows PowerShell and working wi...Basic commands for powershell : Configuring Windows PowerShell and working wi...
Basic commands for powershell : Configuring Windows PowerShell and working wi...
 

Similar to Template Toolkit

Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
dwm042
 
Create a web-app with Cgi Appplication
Create a web-app with Cgi AppplicationCreate a web-app with Cgi Appplication
Create a web-app with Cgi Appplication
olegmmiller
 
Changing Template Engine
Changing Template EngineChanging Template Engine
Changing Template Engine
Takatsugu Shigeta
 
Automation tips
Automation tipsAutomation tips
Automation tips
Ritu Mangla
 
Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
Muhamad Al Imran
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Muhamad Al Imran
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Muhamad Al Imran
 
course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpoint
webhostingguy
 
Into The Box 2018 - CBT
Into The Box 2018 - CBTInto The Box 2018 - CBT
Into The Box 2018 - CBT
Ortus Solutions, Corp
 
Php
PhpPhp
JSP diana y yo
JSP diana y yoJSP diana y yo
JSP diana y yo
michael
 
Presentation log4 j
Presentation log4 jPresentation log4 j
Presentation log4 j
Sylvain Bouchard
 
Presentation log4 j
Presentation log4 jPresentation log4 j
Presentation log4 j
Sylvain Bouchard
 
Php
PhpPhp
Love Twig
Love TwigLove Twig
Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress
Maurizio Pelizzone
 
A Presentation about Puppet that I've made at the OSSPAC conference
A Presentation about Puppet that I've made at the OSSPAC conferenceA Presentation about Puppet that I've made at the OSSPAC conference
A Presentation about Puppet that I've made at the OSSPAC conference
ohadlevy
 
Twig for Drupal @ Frontendunited Amsterdam 2012
Twig for Drupal @ Frontendunited Amsterdam 2012Twig for Drupal @ Frontendunited Amsterdam 2012
Twig for Drupal @ Frontendunited Amsterdam 2012
Rene Bakx
 
Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Php
funkatron
 
Krazykoder struts2 plugins
Krazykoder struts2 pluginsKrazykoder struts2 plugins
Krazykoder struts2 plugins
Krazy Koder
 

Similar to Template Toolkit (20)

Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
 
Create a web-app with Cgi Appplication
Create a web-app with Cgi AppplicationCreate a web-app with Cgi Appplication
Create a web-app with Cgi Appplication
 
Changing Template Engine
Changing Template EngineChanging Template Engine
Changing Template Engine
 
Automation tips
Automation tipsAutomation tips
Automation tips
 
Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
 
course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpoint
 
Into The Box 2018 - CBT
Into The Box 2018 - CBTInto The Box 2018 - CBT
Into The Box 2018 - CBT
 
Php
PhpPhp
Php
 
JSP diana y yo
JSP diana y yoJSP diana y yo
JSP diana y yo
 
Presentation log4 j
Presentation log4 jPresentation log4 j
Presentation log4 j
 
Presentation log4 j
Presentation log4 jPresentation log4 j
Presentation log4 j
 
Php
PhpPhp
Php
 
Love Twig
Love TwigLove Twig
Love Twig
 
Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress
 
A Presentation about Puppet that I've made at the OSSPAC conference
A Presentation about Puppet that I've made at the OSSPAC conferenceA Presentation about Puppet that I've made at the OSSPAC conference
A Presentation about Puppet that I've made at the OSSPAC conference
 
Twig for Drupal @ Frontendunited Amsterdam 2012
Twig for Drupal @ Frontendunited Amsterdam 2012Twig for Drupal @ Frontendunited Amsterdam 2012
Twig for Drupal @ Frontendunited Amsterdam 2012
 
Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Php
 
Krazykoder struts2 plugins
Krazykoder struts2 pluginsKrazykoder struts2 plugins
Krazykoder struts2 plugins
 

Recently uploaded

Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 

Recently uploaded (20)

Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 

Template Toolkit

  • 2.
  • 4. Output is as you wanted
  • 5.
  • 6.
  • 10.
  • 11.
  • 16.
  • 17. Usable through a number of web frameworks
  • 18.
  • 19.
  • 21.
  • 22. Installed as part of the standard Catalyst installation.
  • 23. Using Template Toolkit #! /usr/bin/perl use strict; use Template; my $tt = Template->new(); my $file = “webpage.tt”; my $vars = { person => 'Sam Spade', book => 'Maltese Falcon' }; $tt->process( $file, $vars ) || die $tt->error();
  • 24. Passing Variables to TT Hashes and arrays should be passed as references: $arrayref = [ 1, 2, 3, 4 ]; $hashref = { foo => 1, bar => 2 }; This is also true within Catalyst
  • 25. Simple example template Dear [%- customer -%], We are introducing five new products we want you to consider: [% product.0 %] [% product.1 %] [% product.2 %] [% product.3 %] [% product.4 %]
  • 26. Pre and post chomp No chomp [% foo %] Pre chomp – removes before current line [%- foo %] Post chomp – removes on current line [% foo -%] Both pre and post chomped [%- foo -%] ^_^
  • 27. Dots dereference components. [% myhash.3.component.7.subcomponent %]
  • 28. TT provides virtual methods. In use, looks like Ruby [% string.length %] [% myhash.keys.sort %] [% hashlist.keys.sort.join(', ') %]
  • 29. TT flow of control These teams have the following quarterbacks: [% FOREACH team IN league.keys.sort -%] [% NEXT UNLESS team.defined -%] [% team.name %]: [% team.qb %] [% IF team.owner -%] This team is owned by [% team.owner -%] [% ELSE -%] This team is owned by a committee. [% END -%] [% END -%]
  • 30.
  • 31. WHILE
  • 35. Variables within TT [% foo = 7 %] [%# Is shorthand for %] [% SET foo = 7 %] [%# array example %] [% mylist = [1,2,3,4,5] %] [%# hash example %] [% name = { first = 'John' last = 'Dough' } %]
  • 36. Comments within TT [% # comment to end of line # more commentary myname = 7 -%] [%# comment until terminating chars %] The space between the % and the # makes a difference.
  • 37. Process and Include directives [%# These add stuff from external files to your document -%] [% PROCESS stuff %] [%# process acts like a source statement in shell. Any variables added have document level scope. %] [% INCLUDE morestuff %] [%# The include statement, by contrast, keeps those variables local to its own included file %]
  • 38. Using PROCESS [% PROCESS commonheader %] My main web page content [% PROCESS ads %] [% PROCESS commonfooter %]
  • 39. TAGS directive [% TAGS mason %] The <% location > party is <% opinion >. ~~~ [%# 2 args to TAGS = start and end directives %] [% TAGS { } %] ~~~ Or in code .. my $tt = Template->new({ START_TAG => quotemeta(''), END_TAG => quotemeta(''), });
  • 40.
  • 41. Template->new({ WRAPPER => 'wrapper.tt' });
  • 42. Similar functionality is provided by Catalyst.
  • 43.
  • 45. META directive [%# Meta allows the inner template to pass information out to a wrapper. %] [% META title = 'This is a math equation' -%]
  • 46. INTERPOLATE flag When set, bare Perl variables can be inserted into text. This is a math equation: $math This flag is off by default.
  • 47. BLOCK directive Useful for simplifying chunks of code that can be included or processed later. [% BLOCK button %] Code for HTML button [% END %] TT has ways to build libraries of BLOCKs.
  • 48. Exception Handling [% TRY %] [% USE DBI(mydb) %] [% CATCH %] Error:: [% error %] [% END %]
  • 49. PERL directive Need to add EVAL_PERL => 1 to constructor to use. [% PERL %] for ( 1 .. 5 ) { print “Hello world!”; } [% END %]
  • 50. PERL directive Template directives within the PERL block are evaluated before the PERL block is. So code like the below is legal. [% PERL %] print “Hello, [% name %] I [% verb %]!”; print “I must eat [% entree %] and [% side %].”; [% END %]
  • 51. RAWPERL directive More efficient, but output restricted to appending to $output variable. Only for TT experts, in general. [% RAWPERL %] Stuff; $output .= “ more data”; [% END %]
  • 52. FILTERS Filters transform data contained with the FILTER block. FILTER html makes text HTML safe <code> [% FILTER html %] Lots of C or shell here & this, >> and << that. [% END %] </code>
  • 53. FILTERS II The | symbol is a shortcut for FILTER and can be used to do inline filtering. [% e = 2.718281828 ; e | format('%0.3f') %]
  • 54. FILTER Examples 1. Convert text to PDF [% FILTER latex(“pdf”) %] Text here [% END %] 2. Add <br /> to all ends of lines [% FILTER html_line_break %] To be or not to be That is the question [% END %]
  • 55. Plugins Implemented via the USE directive. [% USE date %] Today is [% date.format %]. [% calc = date.calc %] [% calc.Monday_of_week(27,2008).join('-') %] [% manip = date.manip %]
  • 56.
  • 57. CGI
  • 60. DBI
  • 62. File
  • 63.
  • 65. Table
  • 66. URL
  • 67. Wrap