SlideShare una empresa de Scribd logo
1 de 19
Descargar para leer sin conexión
Smarty
Mustafa Kırımlı
Smarty Basics
{* this is a comment *}

{* this multiline smarty
comment is
not sent to browser
*}
{* The header file with the main logo and stuff *}
{include file='header.tpl'}
{* Dev note: the $includeFile var is assigned in foo.php script *}
<!-- Displays main content block -->
{include file=$includeFile}
Smarty Access Variables
{$foo}
<-- displaying a simple variable (non array/object)
{$foo[4]} <-- display the 5th element of a zero-indexed array
{$foo.bar} <-- display the "bar" key value of an array, similar to PHP $foo['bar']
{$foo.$bar} <-- display variable key value of an array, similar to PHP $foo[$bar]
{$foo->bar} <-- display the object property "bar"
{$foo->bar()} <-- display the return value of object method "bar"
{#foo#}
<-- display the config file variable "foo"
{$smarty.config.foo} <-- synonym for {#foo#}
{$foo[bar]} <-- syntax only valid in a section loop, see {section}
{assign var=foo value='baa'}{$foo} <-- displays "baa", see {assign}
Smarty Access Variables
{$foo.bar.baz}
{$foo.$bar.$baz}
{$foo[4].baz}
{$foo[4].$baz}
{$foo.bar.baz[4]}
{$foo->bar($baz,2,$bar)} <-- passing parameters
{"foo"}
<-- static values are allowed
PHP-like syntax, alternative to "dot" syntax:
{$foo[1]}
// normal access
{$foo['bar']}
{$foo['bar'][1]}
{$foo[$x+$x]}
// index may contain any expression
{$foo[$bar[1]]}
// nested index
{$foo[section_name]} // smarty {section} access, not array access!
Smarty PHP Variables
{* display the server variable "SERVER_NAME" ($_SERVER['SERVER_NAME'])*}
{$smarty.server.SERVER_NAME}
Object chaining:
{$object->method1($x)->method2($y)}
Direct PHP function access:
{time()}
<?php define('MY_CONST_VAL','CHERRIES'); // the constant defined in php ?>
{$smarty.const.MY_CONST_VAL}
Smarty Superglobals
{* display value of page from URL ($_GET) http://www.example.com/index.php?page=foo *}
{$smarty.get.page}
{* display the variable "page" from a form ($_POST['page']) *}
{$smarty.post.page}
{* display the value of the cookie "username" ($_COOKIE['username']) *}
{$smarty.cookies.username}
{* display the server variable "SERVER_NAME" ($_SERVER['SERVER_NAME'])*}
{$smarty.server.SERVER_NAME}
{* display the system environment variable "PATH" *}
{$smarty.env.PATH}
{* display the php session variable "id" ($_SESSION['id']) *}
{$smarty.session.id}
{* display the variable "username" from merged get/post/cookies/server/env *}
{$smarty.request.username}
Smarty {literal}
<script>
// the following braces are ignored by Smarty
// since they are surrounded by whitespace
function foobar {
alert('foobar!');
}
// this one will need literal escapement
{literal}
function bazzy {alert('foobar!');}
{/literal}
</script>
Smarty {php}
{* this template includes a {php} block that assign's the variable $varX
*}
{php}
global $foo, $bar;
if($foo == $bar){
echo 'This will be sent to browser';
}
// assign a variable to Smarty
$this->assign('varX','Toffee');
{/php}
{* output the variable *}
<strong>{$varX}</strong> is my fav ice cream :-)
Smarty |replace
<?php
$smarty->assign('articleTitle', "Child's Stool Great for Use in Garden.");
?>
Smarty:
{$articleTitle}
{$articleTitle|replace:'Garden':'Vineyard'}
{$articleTitle|replace:' ':' '}
Output:
Child's Stool Great for Use in Garden.
Child's Stool Great for Use in Vineyard.
Child's Stool Great for Use in Garden.
Smarty |truncate
<?php
$smarty->assign('articleTitle', 'Two Sisters Reunite after Eighteen Years at Checkout Counter.');
?>
{$articleTitle}
{$articleTitle|truncate}
{$articleTitle|truncate:30}
{$articleTitle|truncate:30:""}
{$articleTitle|truncate:30:"---"}
{$articleTitle|truncate:30:"":true}
{$articleTitle|truncate:30:"...":true}
{$articleTitle|truncate:30:'..':true:true}
Two Sisters Reunite after Eighteen Years at Checkout Counter.
Two Sisters Reunite after Eighteen Years at Checkout Counter.
Two Sisters Reunite after...
Two Sisters Reunite after
Two Sisters Reunite after--Two Sisters Reunite after Eigh
Two Sisters Reunite after E...
Two Sisters Re..ckout Counter.
Smarty |upper|lower
{$articleTitle}
{$articleTitle|lower}
{$articleTitle}
{$articleTitle|upper}
Smarty {html_table}
<?php
$smarty->assign( 'data', array(1,2,3,4,5,6,7,8,9) );
$smarty->assign( 'tr', array('bgcolor="#eeeeee"','bgcolor="#dddddd"') );
$smarty->display('index.tpl');
?>
{**** Example One ****}
{html_table loop=$data}
<table border="1">
<tbody>
<tr><td>1</td><td>2</td><td>3</td></tr>
<tr><td>4</td><td>5</td><td>6</td></tr>
<tr><td>7</td><td>8</td><td>9</td></tr>
</tbody>
</table>
Smarty {html_table}
{**** Example Two ****}
{html_table loop=$data cols=4 table_attr='border="0"'}
<table border="0">
<tbody>
<tr><td>1</td><td>2</td><td>3</td><td>4</td></tr>
<tr><td>5</td><td>6</td><td>7</td><td>8</td></tr>
<tr><td>9</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
</tbody>
</table>
Smarty {html_table}
{**** Example Three ****}
{html_table loop=$data cols="first,second,third,fourth" tr_attr=$tr}
<table border="1">
<thead>
<tr>
<th>first</th><th>second</th><th>third</th><th>fourth</th>
</tr>
</thead>
<tbody>
<tr bgcolor="#eeeeee"><td>1</td><td>2</td><td>3</td><td>4</td></tr>
<tr bgcolor="#dddddd"><td>5</td><td>6</td><td>7</td><td>8</td></tr>
<tr bgcolor="#eeeeee"><td>9</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
</tbody>
</table>
Smarty {html_options}
<?php
$smarty->assign('myOptions', array(
1800 => 'Joe Schmoe',
9904 => 'Jack Smith',
2003 => 'Charlie Brown')
);
$smarty->assign('mySelect', 9904);
?>
Smarty:
{html_options name=foo options=$myOptions selected=$mySelect}
Output:
<select name="foo">
<option value="1800">Joe Schmoe</option>
<option value="9904" selected="selected">Jack Smith</option>
<option value="2003">Charlie Brown</option>
</select>
Template Inheritance (layout.tpl)
<html>
<head>
<title>{block name=title}Default Page Title{/block}</title>
{block name=head}{/block}
</head>
<body>
{block name=body}{/block}
</body>
</html>
Template Inheritance (onecolumn.tpl)
{extends file='layout.tpl'}
{block name=head}
<link href="/css/site.css" rel="stylesheet" type="text/css"/>
<script src="/js/site.js"></script>
{/block}
Template Inheritance (homepage.tpl)
{extends file=onecolumn.tpl'}
{block name=title}My Page Title{/block}
{block name=head}
<link href="/css/homepage.css" rel="stylesheet" type="text/css"/>
<script src="/js/homepage.js"></script>
{/block}
{block name=body}My HTML Page Body goes here{/block}
$smarty->display(homepage.tpl');
Template Inheritance {append}
{extends file=onecolumn.tpl'}
{block name=title}My Page Title{/block}
{block name=head append}
<link href="/css/homepage.css" rel="stylesheet" type="text/css"/>
<script src="/js/homepage.js"></script>
{/block}
{block name=body}My HTML Page Body goes here{/block}
$smarty->display(homepage.tpl');

Más contenido relacionado

La actualidad más candente

Intro to php
Intro to phpIntro to php
Intro to phpSp Singh
 
Web technology html5 php_mysql
Web technology html5 php_mysqlWeb technology html5 php_mysql
Web technology html5 php_mysqldurai arasan
 
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...webhostingguy
 
PHP Workshop Notes
PHP Workshop NotesPHP Workshop Notes
PHP Workshop NotesPamela Fox
 
Total World Domination with i18n (es)
Total World Domination with i18n (es)Total World Domination with i18n (es)
Total World Domination with i18n (es)Zé Fontainhas
 
Introducation to php for beginners
Introducation to php for beginners Introducation to php for beginners
Introducation to php for beginners musrath mohammad
 
Short Intro to PHP and MySQL
Short Intro to PHP and MySQLShort Intro to PHP and MySQL
Short Intro to PHP and MySQLJussi Pohjolainen
 
07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboardsDenis Ristic
 
News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 WorldFabien Potencier
 
Refactoring using Codeception
Refactoring using CodeceptionRefactoring using Codeception
Refactoring using CodeceptionJeroen van Dijk
 

La actualidad más candente (20)

Intro to PHP
Intro to PHPIntro to PHP
Intro to PHP
 
Intro to php
Intro to phpIntro to php
Intro to php
 
Web technology html5 php_mysql
Web technology html5 php_mysqlWeb technology html5 php_mysql
Web technology html5 php_mysql
 
Sa
SaSa
Sa
 
Zero to SOLID
Zero to SOLIDZero to SOLID
Zero to SOLID
 
My cool new Slideshow!
My cool new Slideshow!My cool new Slideshow!
My cool new Slideshow!
 
slidesharenew1
slidesharenew1slidesharenew1
slidesharenew1
 
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
 
PHP Workshop Notes
PHP Workshop NotesPHP Workshop Notes
PHP Workshop Notes
 
Php with my sql
Php with my sqlPhp with my sql
Php with my sql
 
Total World Domination with i18n (es)
Total World Domination with i18n (es)Total World Domination with i18n (es)
Total World Domination with i18n (es)
 
Introducation to php for beginners
Introducation to php for beginners Introducation to php for beginners
Introducation to php for beginners
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
Intermediate PHP
Intermediate PHPIntermediate PHP
Intermediate PHP
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
Short Intro to PHP and MySQL
Short Intro to PHP and MySQLShort Intro to PHP and MySQL
Short Intro to PHP and MySQL
 
07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards
 
News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 World
 
Refactoring using Codeception
Refactoring using CodeceptionRefactoring using Codeception
Refactoring using Codeception
 
PHP for hacks
PHP for hacksPHP for hacks
PHP for hacks
 

Destacado (8)

Smarty + PHP
Smarty + PHPSmarty + PHP
Smarty + PHP
 
jQuery für Anfänger
jQuery für AnfängerjQuery für Anfänger
jQuery für Anfänger
 
Smarty 2
Smarty 2Smarty 2
Smarty 2
 
How to Use PHP Smarty Template
How to Use PHP Smarty TemplateHow to Use PHP Smarty Template
How to Use PHP Smarty Template
 
Smarty
SmartySmarty
Smarty
 
Deploying PHP applications with Phing
Deploying PHP applications with PhingDeploying PHP applications with Phing
Deploying PHP applications with Phing
 
Framework Auswahlkriterin, PHP Unconference 2009 in Hamburg
Framework Auswahlkriterin, PHP Unconference 2009 in Hamburg Framework Auswahlkriterin, PHP Unconference 2009 in Hamburg
Framework Auswahlkriterin, PHP Unconference 2009 in Hamburg
 
Building and deploying PHP applications with Phing
Building and deploying PHP applications with PhingBuilding and deploying PHP applications with Phing
Building and deploying PHP applications with Phing
 

Similar a Smarty Template Engine

Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)Fabien Potencier
 
Alessandro sf 2010
Alessandro sf 2010Alessandro sf 2010
Alessandro sf 2010Puppet
 
PHP 5.3 And PHP 6 A Look Ahead
PHP 5.3 And PHP 6 A Look AheadPHP 5.3 And PHP 6 A Look Ahead
PHP 5.3 And PHP 6 A Look Aheadthinkphp
 
Nashvile Symfony Routes Presentation
Nashvile Symfony Routes PresentationNashvile Symfony Routes Presentation
Nashvile Symfony Routes PresentationBrent Shaffer
 
The Origin of Lithium
The Origin of LithiumThe Origin of Lithium
The Origin of LithiumNate Abele
 
Aura Project for PHP
Aura Project for PHPAura Project for PHP
Aura Project for PHPHari K T
 
Puppet Camp LA 2015: Basic Puppet Module Design (Beginner)
Puppet Camp LA  2015: Basic Puppet Module Design (Beginner)Puppet Camp LA  2015: Basic Puppet Module Design (Beginner)
Puppet Camp LA 2015: Basic Puppet Module Design (Beginner)Puppet
 
Puppetcamp module design talk
Puppetcamp module design talkPuppetcamp module design talk
Puppetcamp module design talkJeremy Kitchen
 
vfsStream - effective filesystem mocking
vfsStream - effective filesystem mocking vfsStream - effective filesystem mocking
vfsStream - effective filesystem mocking Sebastian Marek
 
Extbase and Beyond
Extbase and BeyondExtbase and Beyond
Extbase and BeyondJochen Rau
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Seri Moth
 
Introducing CakeEntity
Introducing CakeEntityIntroducing CakeEntity
Introducing CakeEntityBasuke Suzuki
 
dcs plus Catalogue 2015
dcs plus Catalogue 2015dcs plus Catalogue 2015
dcs plus Catalogue 2015dcs plus
 
C A S Sample Php
C A S Sample PhpC A S Sample Php
C A S Sample PhpJH Lee
 
Get into the FLOW with Extbase
Get into the FLOW with ExtbaseGet into the FLOW with Extbase
Get into the FLOW with ExtbaseJochen Rau
 
SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Developmentjsmith92
 
Advanced symfony Techniques
Advanced symfony TechniquesAdvanced symfony Techniques
Advanced symfony TechniquesKris Wallsmith
 

Similar a Smarty Template Engine (20)

Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)
 
Alessandro sf 2010
Alessandro sf 2010Alessandro sf 2010
Alessandro sf 2010
 
PHP 5.3 And PHP 6 A Look Ahead
PHP 5.3 And PHP 6 A Look AheadPHP 5.3 And PHP 6 A Look Ahead
PHP 5.3 And PHP 6 A Look Ahead
 
Nashvile Symfony Routes Presentation
Nashvile Symfony Routes PresentationNashvile Symfony Routes Presentation
Nashvile Symfony Routes Presentation
 
The Origin of Lithium
The Origin of LithiumThe Origin of Lithium
The Origin of Lithium
 
Aura Project for PHP
Aura Project for PHPAura Project for PHP
Aura Project for PHP
 
Smarty 3 overview
Smarty 3 overviewSmarty 3 overview
Smarty 3 overview
 
Puppet Camp LA 2015: Basic Puppet Module Design (Beginner)
Puppet Camp LA  2015: Basic Puppet Module Design (Beginner)Puppet Camp LA  2015: Basic Puppet Module Design (Beginner)
Puppet Camp LA 2015: Basic Puppet Module Design (Beginner)
 
Puppetcamp module design talk
Puppetcamp module design talkPuppetcamp module design talk
Puppetcamp module design talk
 
vfsStream - effective filesystem mocking
vfsStream - effective filesystem mocking vfsStream - effective filesystem mocking
vfsStream - effective filesystem mocking
 
Extbase and Beyond
Extbase and BeyondExtbase and Beyond
Extbase and Beyond
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
 
Introducing CakeEntity
Introducing CakeEntityIntroducing CakeEntity
Introducing CakeEntity
 
dcs plus Catalogue 2015
dcs plus Catalogue 2015dcs plus Catalogue 2015
dcs plus Catalogue 2015
 
C A S Sample Php
C A S Sample PhpC A S Sample Php
C A S Sample Php
 
Get into the FLOW with Extbase
Get into the FLOW with ExtbaseGet into the FLOW with Extbase
Get into the FLOW with Extbase
 
SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Development
 
Advanced symfony Techniques
Advanced symfony TechniquesAdvanced symfony Techniques
Advanced symfony Techniques
 
ReUse Your (Puppet) Modules!
ReUse Your (Puppet) Modules!ReUse Your (Puppet) Modules!
ReUse Your (Puppet) Modules!
 
Introduction in php part 2
Introduction in php part 2Introduction in php part 2
Introduction in php part 2
 

Más de Mustafa Kırımlı (8)

Compute @ edge
Compute @ edgeCompute @ edge
Compute @ edge
 
Why and Way of Using Docker & Kubernetes
Why and Way of Using Docker & KubernetesWhy and Way of Using Docker & Kubernetes
Why and Way of Using Docker & Kubernetes
 
Running kubernetes
Running kubernetesRunning kubernetes
Running kubernetes
 
Spot instances on kubernetes
Spot instances on kubernetesSpot instances on kubernetes
Spot instances on kubernetes
 
Opsiyonlar
OpsiyonlarOpsiyonlar
Opsiyonlar
 
PHP Dosya Yükleme
PHP Dosya YüklemePHP Dosya Yükleme
PHP Dosya Yükleme
 
HTML ve CSS
HTML ve CSSHTML ve CSS
HTML ve CSS
 
Http Yaşam Döngüsü
Http Yaşam DöngüsüHttp Yaşam Döngüsü
Http Yaşam Döngüsü
 

Último

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 

Último (20)

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

Smarty Template Engine

  • 2. Smarty Basics {* this is a comment *} {* this multiline smarty comment is not sent to browser *} {* The header file with the main logo and stuff *} {include file='header.tpl'} {* Dev note: the $includeFile var is assigned in foo.php script *} <!-- Displays main content block --> {include file=$includeFile}
  • 3. Smarty Access Variables {$foo} <-- displaying a simple variable (non array/object) {$foo[4]} <-- display the 5th element of a zero-indexed array {$foo.bar} <-- display the "bar" key value of an array, similar to PHP $foo['bar'] {$foo.$bar} <-- display variable key value of an array, similar to PHP $foo[$bar] {$foo->bar} <-- display the object property "bar" {$foo->bar()} <-- display the return value of object method "bar" {#foo#} <-- display the config file variable "foo" {$smarty.config.foo} <-- synonym for {#foo#} {$foo[bar]} <-- syntax only valid in a section loop, see {section} {assign var=foo value='baa'}{$foo} <-- displays "baa", see {assign}
  • 4. Smarty Access Variables {$foo.bar.baz} {$foo.$bar.$baz} {$foo[4].baz} {$foo[4].$baz} {$foo.bar.baz[4]} {$foo->bar($baz,2,$bar)} <-- passing parameters {"foo"} <-- static values are allowed PHP-like syntax, alternative to "dot" syntax: {$foo[1]} // normal access {$foo['bar']} {$foo['bar'][1]} {$foo[$x+$x]} // index may contain any expression {$foo[$bar[1]]} // nested index {$foo[section_name]} // smarty {section} access, not array access!
  • 5. Smarty PHP Variables {* display the server variable "SERVER_NAME" ($_SERVER['SERVER_NAME'])*} {$smarty.server.SERVER_NAME} Object chaining: {$object->method1($x)->method2($y)} Direct PHP function access: {time()} <?php define('MY_CONST_VAL','CHERRIES'); // the constant defined in php ?> {$smarty.const.MY_CONST_VAL}
  • 6. Smarty Superglobals {* display value of page from URL ($_GET) http://www.example.com/index.php?page=foo *} {$smarty.get.page} {* display the variable "page" from a form ($_POST['page']) *} {$smarty.post.page} {* display the value of the cookie "username" ($_COOKIE['username']) *} {$smarty.cookies.username} {* display the server variable "SERVER_NAME" ($_SERVER['SERVER_NAME'])*} {$smarty.server.SERVER_NAME} {* display the system environment variable "PATH" *} {$smarty.env.PATH} {* display the php session variable "id" ($_SESSION['id']) *} {$smarty.session.id} {* display the variable "username" from merged get/post/cookies/server/env *} {$smarty.request.username}
  • 7. Smarty {literal} <script> // the following braces are ignored by Smarty // since they are surrounded by whitespace function foobar { alert('foobar!'); } // this one will need literal escapement {literal} function bazzy {alert('foobar!');} {/literal} </script>
  • 8. Smarty {php} {* this template includes a {php} block that assign's the variable $varX *} {php} global $foo, $bar; if($foo == $bar){ echo 'This will be sent to browser'; } // assign a variable to Smarty $this->assign('varX','Toffee'); {/php} {* output the variable *} <strong>{$varX}</strong> is my fav ice cream :-)
  • 9. Smarty |replace <?php $smarty->assign('articleTitle', "Child's Stool Great for Use in Garden."); ?> Smarty: {$articleTitle} {$articleTitle|replace:'Garden':'Vineyard'} {$articleTitle|replace:' ':' '} Output: Child's Stool Great for Use in Garden. Child's Stool Great for Use in Vineyard. Child's Stool Great for Use in Garden.
  • 10. Smarty |truncate <?php $smarty->assign('articleTitle', 'Two Sisters Reunite after Eighteen Years at Checkout Counter.'); ?> {$articleTitle} {$articleTitle|truncate} {$articleTitle|truncate:30} {$articleTitle|truncate:30:""} {$articleTitle|truncate:30:"---"} {$articleTitle|truncate:30:"":true} {$articleTitle|truncate:30:"...":true} {$articleTitle|truncate:30:'..':true:true} Two Sisters Reunite after Eighteen Years at Checkout Counter. Two Sisters Reunite after Eighteen Years at Checkout Counter. Two Sisters Reunite after... Two Sisters Reunite after Two Sisters Reunite after--Two Sisters Reunite after Eigh Two Sisters Reunite after E... Two Sisters Re..ckout Counter.
  • 12. Smarty {html_table} <?php $smarty->assign( 'data', array(1,2,3,4,5,6,7,8,9) ); $smarty->assign( 'tr', array('bgcolor="#eeeeee"','bgcolor="#dddddd"') ); $smarty->display('index.tpl'); ?> {**** Example One ****} {html_table loop=$data} <table border="1"> <tbody> <tr><td>1</td><td>2</td><td>3</td></tr> <tr><td>4</td><td>5</td><td>6</td></tr> <tr><td>7</td><td>8</td><td>9</td></tr> </tbody> </table>
  • 13. Smarty {html_table} {**** Example Two ****} {html_table loop=$data cols=4 table_attr='border="0"'} <table border="0"> <tbody> <tr><td>1</td><td>2</td><td>3</td><td>4</td></tr> <tr><td>5</td><td>6</td><td>7</td><td>8</td></tr> <tr><td>9</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr> </tbody> </table>
  • 14. Smarty {html_table} {**** Example Three ****} {html_table loop=$data cols="first,second,third,fourth" tr_attr=$tr} <table border="1"> <thead> <tr> <th>first</th><th>second</th><th>third</th><th>fourth</th> </tr> </thead> <tbody> <tr bgcolor="#eeeeee"><td>1</td><td>2</td><td>3</td><td>4</td></tr> <tr bgcolor="#dddddd"><td>5</td><td>6</td><td>7</td><td>8</td></tr> <tr bgcolor="#eeeeee"><td>9</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr> </tbody> </table>
  • 15. Smarty {html_options} <?php $smarty->assign('myOptions', array( 1800 => 'Joe Schmoe', 9904 => 'Jack Smith', 2003 => 'Charlie Brown') ); $smarty->assign('mySelect', 9904); ?> Smarty: {html_options name=foo options=$myOptions selected=$mySelect} Output: <select name="foo"> <option value="1800">Joe Schmoe</option> <option value="9904" selected="selected">Jack Smith</option> <option value="2003">Charlie Brown</option> </select>
  • 16. Template Inheritance (layout.tpl) <html> <head> <title>{block name=title}Default Page Title{/block}</title> {block name=head}{/block} </head> <body> {block name=body}{/block} </body> </html>
  • 17. Template Inheritance (onecolumn.tpl) {extends file='layout.tpl'} {block name=head} <link href="/css/site.css" rel="stylesheet" type="text/css"/> <script src="/js/site.js"></script> {/block}
  • 18. Template Inheritance (homepage.tpl) {extends file=onecolumn.tpl'} {block name=title}My Page Title{/block} {block name=head} <link href="/css/homepage.css" rel="stylesheet" type="text/css"/> <script src="/js/homepage.js"></script> {/block} {block name=body}My HTML Page Body goes here{/block} $smarty->display(homepage.tpl');
  • 19. Template Inheritance {append} {extends file=onecolumn.tpl'} {block name=title}My Page Title{/block} {block name=head append} <link href="/css/homepage.css" rel="stylesheet" type="text/css"/> <script src="/js/homepage.js"></script> {/block} {block name=body}My HTML Page Body goes here{/block} $smarty->display(homepage.tpl');