SlideShare a Scribd company logo
Smarty Template Introduction Musavir Iftekhar
Installation Download form site.. www. smarty .net/  Unzip and put smarty directory under your home directory
Using Better to create your own folders of templates else using default. <?php define ( 'SMARTY_DIR', 'smarty/'  ); require_once ( SMARTY_DIR  .  'Smarty.class.php '); $smarty  = new Smarty(); $smarty->template_dir   =   './templates/'; $smarty->compile_dir   =   './templates/compile/'; $smarty->cache_dir   =   './templates/cache/'; $smarty->caching   =   false; ?>
Common syntax  $val = “some value”; $smarty->assign(“smarty_sending_var”, $val); $smarty->display(“page.tpl”);// page in template folder ------------------------------------------------------- Page.tpl {* these are comments of smarty *} {$smarty_sending_var} //  will show contents of sending values from the page
Variable Modifiers {$var|modifier} {$title|capitalize} output: MYTITLE {$title|count_words} output: 55 {$dt, “%B %e, %Y”} output:  December 22, 2005 {$title|default:”some val”} output: if $title = null then some val {$title|strip_tags} output:  remove html tags from string {$title|truncate:20}  output: show reduce to 20 characters
Control Structures {if $var qualifier comprator} Output {elseif $var qualifier comprator} Output {else} Output {/if}
$my_array = array(‘val1’, ‘val2’, ‘val3’); $smarty->assign(“array_val”, $my_array); Handle in into template as {foreach from=$my_array item=valout} {$valout} {/foreach} If no value in array.. then {foreach from=$my_array item=valout} {$valout} {foreachesles} Output here {/foreach}
Section $titles = arrray(‘a’, ‘b’, ‘c’); $smarty->assign(“titles”, $titles); $smarty->display(“titles.tpl”); --------------------titles.tpl-------------------- {section name=book loop=$titles} {$titles[book]} {/section} Output:abc
$titles = arrray(‘title’=>’Eng’, ‘author’=>’Master’, ‘pub’=>’apex’); $smarty->assign(“titles”, $titles); $smarty->display(“titles.tpl”); --------------------titles.tpl-------------------- {section name=book loop=$titles} {$titles[book].title} {$titles[book].author} {$titles[book].pub} {/section} Output:Eng Master apex
sectionelse $titles = arrray(‘a’, ‘b’, ‘c’); $smarty->assign(“titles”, $titles); $smarty->display(“titles.tpl”); --------------------titles.tpl-------------------- {section name=book loop=$titles} {$titles[book]} {sectionelse} Output: if array = null {/section} Output:abc
Include {include file=“/usr/local/lib/pmnp/header.tpl”} {* Execute some other Smarty statements here. *} {include file=“/usr/local/temps/footer.tpl”} {include file=“/local/header.tpl” title=“My home page”}
Insert Insert some advertisement page function insert_banner(){ } ------------------tpl file----------------------------- <img src=“imgs/{insert name=“banner”}.gif”/>
CSS with literal tag Insert css into tpl file directly <html><head> {literal}<style type=“text/css”> P{Margin: 5px;} </style> {/literal} </head> User Link to connect with outer css file  <link style=“text/css” href=“mycss.css” />
Caches $smarty->caching = 1

More Related Content

PDF
Laravel collections an overview - Laravel SP
Matheus Marabesi
 
PPTX
Let's write secure Drupal code!
Balázs Tatár
 
PDF
PHP object calisthenics
Giorgio Cefaro
 
PDF
Shortcodes In-Depth
Micah Wood
 
KEY
Fields in Core: How to create a custom field
Ivan Zugec
 
PPT
Arrays in php
Laiby Thomas
 
PPT
Class 4 - PHP Arrays
Ahmed Swilam
 
PDF
Drupal 8: Routing & More
drubb
 
Laravel collections an overview - Laravel SP
Matheus Marabesi
 
Let's write secure Drupal code!
Balázs Tatár
 
PHP object calisthenics
Giorgio Cefaro
 
Shortcodes In-Depth
Micah Wood
 
Fields in Core: How to create a custom field
Ivan Zugec
 
Arrays in php
Laiby Thomas
 
Class 4 - PHP Arrays
Ahmed Swilam
 
Drupal 8: Routing & More
drubb
 

What's hot (20)

PDF
Sorting arrays in PHP
Vineet Kumar Saini
 
PDF
PHP 101
Muhammad Hijazi
 
PPTX
PHP Functions & Arrays
Henry Osborne
 
TXT
Daily notes
meghendra168
 
PDF
Drupal 8: Forms
drubb
 
ODP
State Machines to State of the Art
Rowan Merewood
 
PDF
Drupal 8 Sample Module
drubb
 
PDF
How to write code you won't hate tomorrow
Pete McFarlane
 
PPT
Arrays in PHP
Compare Infobase Limited
 
PDF
Apostrophe
tompunk
 
KEY
$.Template
Dave Furfero
 
PDF
Arrays in PHP
Vineet Kumar Saini
 
PDF
[PL] Jak nie zostać "programistą" PHP?
Radek Benkel
 
PPTX
Views notwithstanding
Srikanth Bangalore
 
PDF
How to count money using PHP and not lose money
Piotr Horzycki
 
PDF
Unittests für Dummies
Lars Jankowfsky
 
PDF
PHP Unit 4 arrays
Kumar
 
PPT
Php Using Arrays
mussawir20
 
PPT
Wc no
Ivelina Dimova
 
PDF
Php array
Nikul Shah
 
Sorting arrays in PHP
Vineet Kumar Saini
 
PHP 101
Muhammad Hijazi
 
PHP Functions & Arrays
Henry Osborne
 
Daily notes
meghendra168
 
Drupal 8: Forms
drubb
 
State Machines to State of the Art
Rowan Merewood
 
Drupal 8 Sample Module
drubb
 
How to write code you won't hate tomorrow
Pete McFarlane
 
Apostrophe
tompunk
 
$.Template
Dave Furfero
 
Arrays in PHP
Vineet Kumar Saini
 
[PL] Jak nie zostać "programistą" PHP?
Radek Benkel
 
Views notwithstanding
Srikanth Bangalore
 
How to count money using PHP and not lose money
Piotr Horzycki
 
Unittests für Dummies
Lars Jankowfsky
 
PHP Unit 4 arrays
Kumar
 
Php Using Arrays
mussawir20
 
Php array
Nikul Shah
 
Ad

Viewers also liked (6)

PDF
A Taste (Test) of ResBos
kleinhsu
 
PPS
Un día como cualquier otro
pazpormexico
 
ODP
Rocket Italian
rocket_italian
 
PPT
Filme.Com
guesta4dfba
 
PPT
Teorema Pyfagora
OvchinnikovaT
 
PPT
Escuela Taller FáTima
acciondetuzona
 
A Taste (Test) of ResBos
kleinhsu
 
Un día como cualquier otro
pazpormexico
 
Rocket Italian
rocket_italian
 
Filme.Com
guesta4dfba
 
Teorema Pyfagora
OvchinnikovaT
 
Escuela Taller FáTima
acciondetuzona
 
Ad

Similar to Smarty Template (20)

PDF
laravel tricks in 50minutes
Barang CK
 
PDF
50 Laravel Tricks in 50 Minutes
Azim Kurt
 
ZIP
Drupal Development (Part 2)
Jeff Eaton
 
PPTX
Smarty
Aravind Vel
 
PDF
Bag of tricks
brian d foy
 
PDF
Perl Bag of Tricks - Baltimore Perl mongers
brian d foy
 
ODP
Aura Project for PHP
Hari K T
 
PDF
Simple Ways To Be A Better Programmer (OSCON 2007)
Michael Schwern
 
PDF
Smarty
Matija Rijavec
 
ODP
vfsStream - effective filesystem mocking
Sebastian Marek
 
KEY
Keeping It Simple
Stephanie Leary
 
PDF
PhpUnit - The most unknown Parts
Bastian Feder
 
KEY
Good Evils In Perl (Yapc Asia)
Kang-min Liu
 
DOCX
Apache Tomcat Shutdown Startup Script Shell
Anar Godjaev
 
PPTX
Tidy Up Your Code
Abbas Ali
 
ODP
Modern Perl
Marcos Rebelo
 
RTF
distill
Thomas Knudstrup
 
PDF
Advanced modulinos
brian d foy
 
KEY
Can't Miss Features of PHP 5.3 and 5.4
Jeff Carouth
 
PPT
PHP
webhostingguy
 
laravel tricks in 50minutes
Barang CK
 
50 Laravel Tricks in 50 Minutes
Azim Kurt
 
Drupal Development (Part 2)
Jeff Eaton
 
Smarty
Aravind Vel
 
Bag of tricks
brian d foy
 
Perl Bag of Tricks - Baltimore Perl mongers
brian d foy
 
Aura Project for PHP
Hari K T
 
Simple Ways To Be A Better Programmer (OSCON 2007)
Michael Schwern
 
vfsStream - effective filesystem mocking
Sebastian Marek
 
Keeping It Simple
Stephanie Leary
 
PhpUnit - The most unknown Parts
Bastian Feder
 
Good Evils In Perl (Yapc Asia)
Kang-min Liu
 
Apache Tomcat Shutdown Startup Script Shell
Anar Godjaev
 
Tidy Up Your Code
Abbas Ali
 
Modern Perl
Marcos Rebelo
 
Advanced modulinos
brian d foy
 
Can't Miss Features of PHP 5.3 and 5.4
Jeff Carouth
 

More from mussawir20 (20)

PPT
Php Operators N Controllers
mussawir20
 
PPT
Php Calling Operators
mussawir20
 
PPT
Database Design Process
mussawir20
 
PPT
Php Simple Xml
mussawir20
 
PPT
Php String And Regular Expressions
mussawir20
 
PPT
Php Sq Lite
mussawir20
 
PPT
Php Sessoins N Cookies
mussawir20
 
PPT
Php Rss
mussawir20
 
PPT
Php Reusing Code And Writing Functions
mussawir20
 
PPT
Php Oop
mussawir20
 
PPT
Php My Sql
mussawir20
 
PPT
Php File Operations
mussawir20
 
PPT
Php Error Handling
mussawir20
 
PPT
Php Crash Course
mussawir20
 
PPT
Php Basic Security
mussawir20
 
PPT
Javascript Oop
mussawir20
 
PPT
Html
mussawir20
 
PPT
Javascript
mussawir20
 
PPT
Object Range
mussawir20
 
PPT
Prototype Utility Methods(1)
mussawir20
 
Php Operators N Controllers
mussawir20
 
Php Calling Operators
mussawir20
 
Database Design Process
mussawir20
 
Php Simple Xml
mussawir20
 
Php String And Regular Expressions
mussawir20
 
Php Sq Lite
mussawir20
 
Php Sessoins N Cookies
mussawir20
 
Php Rss
mussawir20
 
Php Reusing Code And Writing Functions
mussawir20
 
Php Oop
mussawir20
 
Php My Sql
mussawir20
 
Php File Operations
mussawir20
 
Php Error Handling
mussawir20
 
Php Crash Course
mussawir20
 
Php Basic Security
mussawir20
 
Javascript Oop
mussawir20
 
Javascript
mussawir20
 
Object Range
mussawir20
 
Prototype Utility Methods(1)
mussawir20
 

Recently uploaded (20)

PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
PDF
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
Software Development Methodologies in 2025
KodekX
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PPTX
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
The Future of Artificial Intelligence (AI)
Mukul
 
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
Software Development Methodologies in 2025
KodekX
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 

Smarty Template

  • 1. Smarty Template Introduction Musavir Iftekhar
  • 2. Installation Download form site.. www. smarty .net/ Unzip and put smarty directory under your home directory
  • 3. Using Better to create your own folders of templates else using default. <?php define ( 'SMARTY_DIR', 'smarty/' ); require_once ( SMARTY_DIR . 'Smarty.class.php '); $smarty = new Smarty(); $smarty->template_dir = './templates/'; $smarty->compile_dir = './templates/compile/'; $smarty->cache_dir = './templates/cache/'; $smarty->caching = false; ?>
  • 4. Common syntax $val = “some value”; $smarty->assign(“smarty_sending_var”, $val); $smarty->display(“page.tpl”);// page in template folder ------------------------------------------------------- Page.tpl {* these are comments of smarty *} {$smarty_sending_var} // will show contents of sending values from the page
  • 5. Variable Modifiers {$var|modifier} {$title|capitalize} output: MYTITLE {$title|count_words} output: 55 {$dt, “%B %e, %Y”} output: December 22, 2005 {$title|default:”some val”} output: if $title = null then some val {$title|strip_tags} output: remove html tags from string {$title|truncate:20} output: show reduce to 20 characters
  • 6. Control Structures {if $var qualifier comprator} Output {elseif $var qualifier comprator} Output {else} Output {/if}
  • 7. $my_array = array(‘val1’, ‘val2’, ‘val3’); $smarty->assign(“array_val”, $my_array); Handle in into template as {foreach from=$my_array item=valout} {$valout} {/foreach} If no value in array.. then {foreach from=$my_array item=valout} {$valout} {foreachesles} Output here {/foreach}
  • 8. Section $titles = arrray(‘a’, ‘b’, ‘c’); $smarty->assign(“titles”, $titles); $smarty->display(“titles.tpl”); --------------------titles.tpl-------------------- {section name=book loop=$titles} {$titles[book]} {/section} Output:abc
  • 9. $titles = arrray(‘title’=>’Eng’, ‘author’=>’Master’, ‘pub’=>’apex’); $smarty->assign(“titles”, $titles); $smarty->display(“titles.tpl”); --------------------titles.tpl-------------------- {section name=book loop=$titles} {$titles[book].title} {$titles[book].author} {$titles[book].pub} {/section} Output:Eng Master apex
  • 10. sectionelse $titles = arrray(‘a’, ‘b’, ‘c’); $smarty->assign(“titles”, $titles); $smarty->display(“titles.tpl”); --------------------titles.tpl-------------------- {section name=book loop=$titles} {$titles[book]} {sectionelse} Output: if array = null {/section} Output:abc
  • 11. Include {include file=“/usr/local/lib/pmnp/header.tpl”} {* Execute some other Smarty statements here. *} {include file=“/usr/local/temps/footer.tpl”} {include file=“/local/header.tpl” title=“My home page”}
  • 12. Insert Insert some advertisement page function insert_banner(){ } ------------------tpl file----------------------------- <img src=“imgs/{insert name=“banner”}.gif”/>
  • 13. CSS with literal tag Insert css into tpl file directly <html><head> {literal}<style type=“text/css”> P{Margin: 5px;} </style> {/literal} </head> User Link to connect with outer css file <link style=“text/css” href=“mycss.css” />