SlideShare uma empresa Scribd logo
1 de 14
{ smarty }
ondo alfry simanjuntak - ondo@701search.com
701search pte ltd - singapore
PHP TEMPLATE ENGINE
{ smarty}
ondo alfry simanjuntak - ondo@701search.com
701search pte ltd - singapore
PHP TEMPLATE ENGINE
give some me reasons to love you
Extremely Fast
Efficient
Smart
Extensible
Configurable
Customizable
Built-in Caching Support
Plugin Architecture
Custom cache handling
Arbitrary Template Sources
{ smarty}
ondo alfry simanjuntak - ondo@701search.com
701search pte ltd - singapore
PHP TEMPLATE ENGINE
Install and Start
Download libraries from www.smarty.net,
requires a web server running PHP 5.2 or greater.
#index.php
require_once('Smarty-3.1.18/libs/Smarty.class.php');
$smarty = new Smarty();
$smarty->template_dir = 'views';
$smarty->compile_dir = 'tmp';
$array = array ( 'Torres' => 28, 'Xavi' => 30, 'Lampard' => 32);
$array ->assign('player', $array);
$smarty->display('index.tpl');
#views/index.tpl
{foreach from=$player key=k item=i}
{$k} = {$i} <br />
{/foreach}
#result
Torres = 28
Xavi = 30
Lampard = 32
{ smarty}
ondo alfry simanjuntak - ondo@701search.com
701search pte ltd - singapore
PHP TEMPLATE ENGINE
Modifiers
Offers neat capability to filtering output within templates. And allows logic layout
to reside inside template rather than being apart of application logic.
{ can applied to any $variables }
{ autoloaded }
{ all php-functions can be used as modifiers implicitly }
{ smarty}
ondo alfry simanjuntak - ondo@701search.com
701search pte ltd - singapore
PHP TEMPLATE ENGINE
Sample Codes
#index.php
$string = 'Hello world';
$date = '2014-04-15';
$array = array ( 'Torres' => 28, 'Xavi' => 30, 'Lampard' => 32);
$array ->assign('hello', $string);
$array ->assign('date', $date);
$array ->assign('player', $array);
#views/index.tpl
{$hello} - {$date|date_format}
{php}
sha1('hello');
{/php}
<table>
{foreach from=$player key=k item=i}
<tr style=”background: {cyle values='silver, gray'}”>
<td>{$k}</td> = <td>{$i} </td>
</tr>
{/foreach}
</table>
{ smarty}
ondo alfry simanjuntak - ondo@701search.com
701search pte ltd - singapore
PHP TEMPLATE ENGINE
Modifiers
#index.php
$smarty ->assign( ‘address’, $_POST[‘address’]);
$smarty->display(‘index.tpl’);
#views/index.tpl
<input type=‘text’ name=‘address’ value=‘{$address|escape|default:”Your address”}’>
Smarty provides very convenient default modifier, which is particularly
useful for populating forms
{ smarty}
ondo alfry simanjuntak - ondo@701search.com
701search pte ltd - singapore
PHP TEMPLATE ENGINE
Merging Templates
#views/index.tpl
{include file=‘header.tpl’ val=‘One’ val2=‘Two’}
{include file=‘footer.tpl’}
Allow templates to references another templates and attributes that
specified in include tag will be made available as smarty variables in
include template
{ smarty}
ondo alfry simanjuntak - ondo@701search.com
701search pte ltd - singapore
PHP TEMPLATE ENGINE
Array Iterations
#index.php
$smarty ->result(‘res’, pg_query($db, ‘SELECT * FROM …’))
#views/index.tpl
{foreach from=$res item=row}
{foreach from=$row key=column item=value}
{$column}: {$value} <br />
{/foreach}
{/foreach}
Entire array structure can be output inside smarty, without involving
the logic portion of the code
{ smarty}
ondo alfry simanjuntak - ondo@701search.com
701search pte ltd - singapore
PHP TEMPLATE ENGINE
Conditional Expressions
{if $name eq 'Fred'}
Welcome Sir.
{elseif $name eq 'Wilma'}
Welcome Ma'am.
{else}
Welcome, whatever you are.
{/if}
{* an example with "or" logic *}
{if $name eq 'Fred' or $name eq 'Wilma'} ... {/if}
{* same as above *}
{if $name == 'Fred' || $name == 'Wilma'} ... {/if}
{* parenthesis are allowed *}
{if ( $amount < 0 or $amount > 1000 ) and $volume >= #minVolAmt#} ... {/if}
Support all operators found in PHP natively ==, ===, !=, !==, <, >,…
{ smarty}
ondo alfry simanjuntak - ondo@701search.com
701search pte ltd - singapore
PHP TEMPLATE ENGINE
Capturing Output
#views/index.tpl
{capture name=admin_opts}
{if $admin ne “”}….{/if}
{/capture}
{foreach item=value from=$val}
{$value}
{if $smarty.capture.admin_opts ne “”}
{$smarty.capture.admin_opts}
{/if}
{/foreach}
Allow to capture output from a block of code in a buffer, and
use it later
{ smarty}
ondo alfry simanjuntak - ondo@701search.com
701search pte ltd - singapore
PHP TEMPLATE ENGINE
Smarty & Javascript
#views/header.tpl
{literal}
<script type=“text/javascript”>
window.location = domain;
</script>
{/literal>
{literal} tag to prevent smarty for intercepting javascript logic
{ smarty}
ondo alfry simanjuntak - ondo@701search.com
701search pte ltd - singapore
PHP TEMPLATE ENGINE
White-space cleanup
#views/index.tpl
{strip}
<table border=“0”>
<tr>
<td>
content
</td>
</tr>
</table>
{/strip>
#result
<table border=“0”><tr><td>content</td></tr></table>
{strip} tag to remove white space that generated by output
{ smarty}
ondo alfry simanjuntak - ondo@701search.com
701search pte ltd - singapore
PHP TEMPLATE ENGINE
Caching
$cache_lifetime
Offer a tool for caching generated text, caching mechanism
controlled via a series of smarty object properties
Provide own cached mechanism (function)
$cache_id
$cache_handler_func $cache_modified_check
Cached data storage directory Cached data duration
Support the If-Modified-Since browser upload header
{ smarty}
ondo alfry simanjuntak - ondo@701search.com
701search pte ltd - singapore
PHP TEMPLATE ENGINE
Cache Settings
Be sure cache storage directory is writeable by web server
$smarty->cache_dir = ‘./cache’ ;
$smarty->cache_lifetime = 600;
$smarty->cache_modified_check = true;
$smarty->caching = true;
if(! $smarty->is_cached( ‘index.tpl’ ) ) {
/*run queries, assign vars, etc …*/
}
$smarty->display( ‘cache.tpl’ );

Mais conteúdo relacionado

Mais procurados

07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboardsDenis Ristic
 
Apostrophe (improved Paris edition)
Apostrophe (improved Paris edition)Apostrophe (improved Paris edition)
Apostrophe (improved Paris edition)tompunk
 
Xenogenetics for PL/SQL - infusing with Java best practices
Xenogenetics for PL/SQL - infusing with Java best practicesXenogenetics for PL/SQL - infusing with Java best practices
Xenogenetics for PL/SQL - infusing with Java best practicesLucas Jellema
 
Curso Symfony - Clase 4
Curso Symfony - Clase 4Curso Symfony - Clase 4
Curso Symfony - Clase 4Javier Eguiluz
 
Php server variables
Php server variablesPhp server variables
Php server variablesJIGAR MAKHIJA
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHPBradley Holt
 
Diving into HHVM Extensions (PHPNW Conference 2015)
Diving into HHVM Extensions (PHPNW Conference 2015)Diving into HHVM Extensions (PHPNW Conference 2015)
Diving into HHVM Extensions (PHPNW Conference 2015)James Titcumb
 
Tadhack madrid June 2014: Joris Swinnen and WebRTC Nederland "Invite my colle...
Tadhack madrid June 2014: Joris Swinnen and WebRTC Nederland "Invite my colle...Tadhack madrid June 2014: Joris Swinnen and WebRTC Nederland "Invite my colle...
Tadhack madrid June 2014: Joris Swinnen and WebRTC Nederland "Invite my colle...Bart Uelen
 
Zend Server: Not just a PHP stack
Zend Server: Not just a PHP stackZend Server: Not just a PHP stack
Zend Server: Not just a PHP stackJeroen van Dijk
 
Zephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensionsZephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensionsMark Baker
 
Phone calls and sms from php
Phone calls and sms from phpPhone calls and sms from php
Phone calls and sms from phpDavid Stockton
 
Code obfuscation, php shells & more
Code obfuscation, php shells & moreCode obfuscation, php shells & more
Code obfuscation, php shells & moreMattias Geniar
 
Dealing With Legacy PHP Applications
Dealing With Legacy PHP ApplicationsDealing With Legacy PHP Applications
Dealing With Legacy PHP ApplicationsViget Labs
 

Mais procurados (20)

New in php 7
New in php 7New in php 7
New in php 7
 
07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards
 
Zero to SOLID
Zero to SOLIDZero to SOLID
Zero to SOLID
 
Data Validation models
Data Validation modelsData Validation models
Data Validation models
 
Apostrophe (improved Paris edition)
Apostrophe (improved Paris edition)Apostrophe (improved Paris edition)
Apostrophe (improved Paris edition)
 
Xenogenetics for PL/SQL - infusing with Java best practices
Xenogenetics for PL/SQL - infusing with Java best practicesXenogenetics for PL/SQL - infusing with Java best practices
Xenogenetics for PL/SQL - infusing with Java best practices
 
Curso Symfony - Clase 4
Curso Symfony - Clase 4Curso Symfony - Clase 4
Curso Symfony - Clase 4
 
Php server variables
Php server variablesPhp server variables
Php server variables
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Diving into HHVM Extensions (PHPNW Conference 2015)
Diving into HHVM Extensions (PHPNW Conference 2015)Diving into HHVM Extensions (PHPNW Conference 2015)
Diving into HHVM Extensions (PHPNW Conference 2015)
 
Tadhack madrid June 2014: Joris Swinnen and WebRTC Nederland "Invite my colle...
Tadhack madrid June 2014: Joris Swinnen and WebRTC Nederland "Invite my colle...Tadhack madrid June 2014: Joris Swinnen and WebRTC Nederland "Invite my colle...
Tadhack madrid June 2014: Joris Swinnen and WebRTC Nederland "Invite my colle...
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Zend Server: Not just a PHP stack
Zend Server: Not just a PHP stackZend Server: Not just a PHP stack
Zend Server: Not just a PHP stack
 
Zephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensionsZephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensions
 
A Phing fairy tale - ConFoo13
A Phing fairy tale - ConFoo13A Phing fairy tale - ConFoo13
A Phing fairy tale - ConFoo13
 
PHP Basic
PHP BasicPHP Basic
PHP Basic
 
PHP - Introduction to PHP
PHP -  Introduction to PHPPHP -  Introduction to PHP
PHP - Introduction to PHP
 
Phone calls and sms from php
Phone calls and sms from phpPhone calls and sms from php
Phone calls and sms from php
 
Code obfuscation, php shells & more
Code obfuscation, php shells & moreCode obfuscation, php shells & more
Code obfuscation, php shells & more
 
Dealing With Legacy PHP Applications
Dealing With Legacy PHP ApplicationsDealing With Legacy PHP Applications
Dealing With Legacy PHP Applications
 

Destaque

Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101Ted Kulp
 
세션 하이재킹
세션 하이재킹세션 하이재킹
세션 하이재킹Yu Yongwoo
 
Telecommunication system
Telecommunication systemTelecommunication system
Telecommunication systemJamilah Abbas
 
Testing RESTful web services with REST Assured
Testing RESTful web services with REST AssuredTesting RESTful web services with REST Assured
Testing RESTful web services with REST AssuredBas Dijkstra
 
Web Server Technologies I: HTTP & Getting Started
Web Server Technologies I: HTTP & Getting StartedWeb Server Technologies I: HTTP & Getting Started
Web Server Technologies I: HTTP & Getting StartedPort80 Software
 
Web Cookies
Web CookiesWeb Cookies
Web Cookiesapwebco
 
Web (HTTP) request to response life cycle
Web (HTTP) request to response life cycleWeb (HTTP) request to response life cycle
Web (HTTP) request to response life cycleGopakumar Kunduveetil
 
Hacking A Web Site And Secure Web Server Techniques Used
Hacking A Web Site And Secure Web Server Techniques UsedHacking A Web Site And Secure Web Server Techniques Used
Hacking A Web Site And Secure Web Server Techniques UsedSiddharth Bhattacharya
 
Apache Web Server Architecture Chaitanya Kulkarni
Apache Web Server Architecture Chaitanya KulkarniApache Web Server Architecture Chaitanya Kulkarni
Apache Web Server Architecture Chaitanya Kulkarniwebhostingguy
 
Penetration testing
Penetration testingPenetration testing
Penetration testingAmmar WK
 
Hacking With Nmap - Scanning Techniques
Hacking With Nmap - Scanning TechniquesHacking With Nmap - Scanning Techniques
Hacking With Nmap - Scanning Techniquesamiable_indian
 
Basics of telecommunication and networking
Basics of telecommunication and networkingBasics of telecommunication and networking
Basics of telecommunication and networkingMilan Padariya
 

Destaque (20)

Nmap scripting engine
Nmap scripting engineNmap scripting engine
Nmap scripting engine
 
Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101
 
세션 하이재킹
세션 하이재킹세션 하이재킹
세션 하이재킹
 
Cmsms, open source & business model
Cmsms, open source & business modelCmsms, open source & business model
Cmsms, open source & business model
 
Telecommunication system
Telecommunication systemTelecommunication system
Telecommunication system
 
Testing RESTful web services with REST Assured
Testing RESTful web services with REST AssuredTesting RESTful web services with REST Assured
Testing RESTful web services with REST Assured
 
Web Server Technologies I: HTTP & Getting Started
Web Server Technologies I: HTTP & Getting StartedWeb Server Technologies I: HTTP & Getting Started
Web Server Technologies I: HTTP & Getting Started
 
Web Cookies
Web CookiesWeb Cookies
Web Cookies
 
Web (HTTP) request to response life cycle
Web (HTTP) request to response life cycleWeb (HTTP) request to response life cycle
Web (HTTP) request to response life cycle
 
Hacking A Web Site And Secure Web Server Techniques Used
Hacking A Web Site And Secure Web Server Techniques UsedHacking A Web Site And Secure Web Server Techniques Used
Hacking A Web Site And Secure Web Server Techniques Used
 
Apache Web Server Architecture Chaitanya Kulkarni
Apache Web Server Architecture Chaitanya KulkarniApache Web Server Architecture Chaitanya Kulkarni
Apache Web Server Architecture Chaitanya Kulkarni
 
Penetration testing
Penetration testingPenetration testing
Penetration testing
 
Cookie and session
Cookie and sessionCookie and session
Cookie and session
 
Sessions and cookies
Sessions and cookiesSessions and cookies
Sessions and cookies
 
Web Server Hardening
Web Server HardeningWeb Server Hardening
Web Server Hardening
 
Mvc architecture
Mvc architectureMvc architecture
Mvc architecture
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
 
REST & RESTful Web Services
REST & RESTful Web ServicesREST & RESTful Web Services
REST & RESTful Web Services
 
Hacking With Nmap - Scanning Techniques
Hacking With Nmap - Scanning TechniquesHacking With Nmap - Scanning Techniques
Hacking With Nmap - Scanning Techniques
 
Basics of telecommunication and networking
Basics of telecommunication and networkingBasics of telecommunication and networking
Basics of telecommunication and networking
 

Semelhante a Smarty sharing-2

Let's write secure Drupal code! - 13.09.2018 @ Drupal Europe, Darmstadt, Germany
Let's write secure Drupal code! - 13.09.2018 @ Drupal Europe, Darmstadt, GermanyLet's write secure Drupal code! - 13.09.2018 @ Drupal Europe, Darmstadt, Germany
Let's write secure Drupal code! - 13.09.2018 @ Drupal Europe, Darmstadt, GermanyBalázs Tatár
 
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Let's write secure Drupal code! - DrupalCamp Oslo, 2018Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Let's write secure Drupal code! - DrupalCamp Oslo, 2018Balázs Tatár
 
User authentication module using php
User authentication module using phpUser authentication module using php
User authentication module using phpRishabh Srivastava
 
Let's write secure Drupal code! - DrupalCamp London 2019
Let's write secure Drupal code! - DrupalCamp London 2019Let's write secure Drupal code! - DrupalCamp London 2019
Let's write secure Drupal code! - DrupalCamp London 2019Balázs Tatár
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php PresentationAlan Pinstein
 
Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010Michelangelo van Dam
 
Let's write secure Drupal code!
Let's write secure Drupal code!Let's write secure Drupal code!
Let's write secure Drupal code!Balázs Tatár
 
Mojolicious - A new hope
Mojolicious - A new hopeMojolicious - A new hope
Mojolicious - A new hopeMarcus Ramberg
 
Quality Use Of Plugin
Quality Use Of PluginQuality Use Of Plugin
Quality Use Of PluginYasuo Harada
 
Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013Michelangelo van Dam
 
Practical PHP by example Jan Leth-Kjaer
Practical PHP by example   Jan Leth-KjaerPractical PHP by example   Jan Leth-Kjaer
Practical PHP by example Jan Leth-KjaerCOMMON Europe
 
Mojolicious, real-time web framework
Mojolicious, real-time web frameworkMojolicious, real-time web framework
Mojolicious, real-time web frameworktaggg
 
How to build a High Performance PSGI/Plack Server
How to build a High Performance PSGI/Plack Server How to build a High Performance PSGI/Plack Server
How to build a High Performance PSGI/Plack Server Masahiro Nagano
 

Semelhante a Smarty sharing-2 (20)

Smarty
SmartySmarty
Smarty
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
Let's write secure Drupal code! - 13.09.2018 @ Drupal Europe, Darmstadt, Germany
Let's write secure Drupal code! - 13.09.2018 @ Drupal Europe, Darmstadt, GermanyLet's write secure Drupal code! - 13.09.2018 @ Drupal Europe, Darmstadt, Germany
Let's write secure Drupal code! - 13.09.2018 @ Drupal Europe, Darmstadt, Germany
 
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Let's write secure Drupal code! - DrupalCamp Oslo, 2018Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
 
Php101
Php101Php101
Php101
 
User authentication module using php
User authentication module using phpUser authentication module using php
User authentication module using php
 
Let's write secure Drupal code! - DrupalCamp London 2019
Let's write secure Drupal code! - DrupalCamp London 2019Let's write secure Drupal code! - DrupalCamp London 2019
Let's write secure Drupal code! - DrupalCamp London 2019
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php Presentation
 
Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010
 
Let's write secure Drupal code!
Let's write secure Drupal code!Let's write secure Drupal code!
Let's write secure Drupal code!
 
Mojolicious - A new hope
Mojolicious - A new hopeMojolicious - A new hope
Mojolicious - A new hope
 
Quality Use Of Plugin
Quality Use Of PluginQuality Use Of Plugin
Quality Use Of Plugin
 
Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013
 
Tutorial_4_PHP
Tutorial_4_PHPTutorial_4_PHP
Tutorial_4_PHP
 
Tutorial_4_PHP
Tutorial_4_PHPTutorial_4_PHP
Tutorial_4_PHP
 
Tutorial_4_PHP
Tutorial_4_PHPTutorial_4_PHP
Tutorial_4_PHP
 
Tutorial_4_PHP
Tutorial_4_PHPTutorial_4_PHP
Tutorial_4_PHP
 
Practical PHP by example Jan Leth-Kjaer
Practical PHP by example   Jan Leth-KjaerPractical PHP by example   Jan Leth-Kjaer
Practical PHP by example Jan Leth-Kjaer
 
Mojolicious, real-time web framework
Mojolicious, real-time web frameworkMojolicious, real-time web framework
Mojolicious, real-time web framework
 
How to build a High Performance PSGI/Plack Server
How to build a High Performance PSGI/Plack Server How to build a High Performance PSGI/Plack Server
How to build a High Performance PSGI/Plack Server
 

Último

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
🐬 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
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 

Último (20)

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
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...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 

Smarty sharing-2

  • 1. { smarty } ondo alfry simanjuntak - ondo@701search.com 701search pte ltd - singapore PHP TEMPLATE ENGINE
  • 2. { smarty} ondo alfry simanjuntak - ondo@701search.com 701search pte ltd - singapore PHP TEMPLATE ENGINE give some me reasons to love you Extremely Fast Efficient Smart Extensible Configurable Customizable Built-in Caching Support Plugin Architecture Custom cache handling Arbitrary Template Sources
  • 3. { smarty} ondo alfry simanjuntak - ondo@701search.com 701search pte ltd - singapore PHP TEMPLATE ENGINE Install and Start Download libraries from www.smarty.net, requires a web server running PHP 5.2 or greater. #index.php require_once('Smarty-3.1.18/libs/Smarty.class.php'); $smarty = new Smarty(); $smarty->template_dir = 'views'; $smarty->compile_dir = 'tmp'; $array = array ( 'Torres' => 28, 'Xavi' => 30, 'Lampard' => 32); $array ->assign('player', $array); $smarty->display('index.tpl'); #views/index.tpl {foreach from=$player key=k item=i} {$k} = {$i} <br /> {/foreach} #result Torres = 28 Xavi = 30 Lampard = 32
  • 4. { smarty} ondo alfry simanjuntak - ondo@701search.com 701search pte ltd - singapore PHP TEMPLATE ENGINE Modifiers Offers neat capability to filtering output within templates. And allows logic layout to reside inside template rather than being apart of application logic. { can applied to any $variables } { autoloaded } { all php-functions can be used as modifiers implicitly }
  • 5. { smarty} ondo alfry simanjuntak - ondo@701search.com 701search pte ltd - singapore PHP TEMPLATE ENGINE Sample Codes #index.php $string = 'Hello world'; $date = '2014-04-15'; $array = array ( 'Torres' => 28, 'Xavi' => 30, 'Lampard' => 32); $array ->assign('hello', $string); $array ->assign('date', $date); $array ->assign('player', $array); #views/index.tpl {$hello} - {$date|date_format} {php} sha1('hello'); {/php} <table> {foreach from=$player key=k item=i} <tr style=”background: {cyle values='silver, gray'}”> <td>{$k}</td> = <td>{$i} </td> </tr> {/foreach} </table>
  • 6. { smarty} ondo alfry simanjuntak - ondo@701search.com 701search pte ltd - singapore PHP TEMPLATE ENGINE Modifiers #index.php $smarty ->assign( ‘address’, $_POST[‘address’]); $smarty->display(‘index.tpl’); #views/index.tpl <input type=‘text’ name=‘address’ value=‘{$address|escape|default:”Your address”}’> Smarty provides very convenient default modifier, which is particularly useful for populating forms
  • 7. { smarty} ondo alfry simanjuntak - ondo@701search.com 701search pte ltd - singapore PHP TEMPLATE ENGINE Merging Templates #views/index.tpl {include file=‘header.tpl’ val=‘One’ val2=‘Two’} {include file=‘footer.tpl’} Allow templates to references another templates and attributes that specified in include tag will be made available as smarty variables in include template
  • 8. { smarty} ondo alfry simanjuntak - ondo@701search.com 701search pte ltd - singapore PHP TEMPLATE ENGINE Array Iterations #index.php $smarty ->result(‘res’, pg_query($db, ‘SELECT * FROM …’)) #views/index.tpl {foreach from=$res item=row} {foreach from=$row key=column item=value} {$column}: {$value} <br /> {/foreach} {/foreach} Entire array structure can be output inside smarty, without involving the logic portion of the code
  • 9. { smarty} ondo alfry simanjuntak - ondo@701search.com 701search pte ltd - singapore PHP TEMPLATE ENGINE Conditional Expressions {if $name eq 'Fred'} Welcome Sir. {elseif $name eq 'Wilma'} Welcome Ma'am. {else} Welcome, whatever you are. {/if} {* an example with "or" logic *} {if $name eq 'Fred' or $name eq 'Wilma'} ... {/if} {* same as above *} {if $name == 'Fred' || $name == 'Wilma'} ... {/if} {* parenthesis are allowed *} {if ( $amount < 0 or $amount > 1000 ) and $volume >= #minVolAmt#} ... {/if} Support all operators found in PHP natively ==, ===, !=, !==, <, >,…
  • 10. { smarty} ondo alfry simanjuntak - ondo@701search.com 701search pte ltd - singapore PHP TEMPLATE ENGINE Capturing Output #views/index.tpl {capture name=admin_opts} {if $admin ne “”}….{/if} {/capture} {foreach item=value from=$val} {$value} {if $smarty.capture.admin_opts ne “”} {$smarty.capture.admin_opts} {/if} {/foreach} Allow to capture output from a block of code in a buffer, and use it later
  • 11. { smarty} ondo alfry simanjuntak - ondo@701search.com 701search pte ltd - singapore PHP TEMPLATE ENGINE Smarty & Javascript #views/header.tpl {literal} <script type=“text/javascript”> window.location = domain; </script> {/literal> {literal} tag to prevent smarty for intercepting javascript logic
  • 12. { smarty} ondo alfry simanjuntak - ondo@701search.com 701search pte ltd - singapore PHP TEMPLATE ENGINE White-space cleanup #views/index.tpl {strip} <table border=“0”> <tr> <td> content </td> </tr> </table> {/strip> #result <table border=“0”><tr><td>content</td></tr></table> {strip} tag to remove white space that generated by output
  • 13. { smarty} ondo alfry simanjuntak - ondo@701search.com 701search pte ltd - singapore PHP TEMPLATE ENGINE Caching $cache_lifetime Offer a tool for caching generated text, caching mechanism controlled via a series of smarty object properties Provide own cached mechanism (function) $cache_id $cache_handler_func $cache_modified_check Cached data storage directory Cached data duration Support the If-Modified-Since browser upload header
  • 14. { smarty} ondo alfry simanjuntak - ondo@701search.com 701search pte ltd - singapore PHP TEMPLATE ENGINE Cache Settings Be sure cache storage directory is writeable by web server $smarty->cache_dir = ‘./cache’ ; $smarty->cache_lifetime = 600; $smarty->cache_modified_check = true; $smarty->caching = true; if(! $smarty->is_cached( ‘index.tpl’ ) ) { /*run queries, assign vars, etc …*/ } $smarty->display( ‘cache.tpl’ );