Smarty

on

  • 496 views

Smarty is a template engine for PHP. This presentation explains the basics of Smarty templating.

Smarty is a template engine for PHP. This presentation explains the basics of Smarty templating.

Statistics

Views

Total Views
496
Views on SlideShare
479
Embed Views
17

Actions

Likes
0
Downloads
18
Comments
0

3 Embeds 17

http://junkasajan.wordpress.com 9
http://www.tumblr.com 4
http://junkasajan.tumblr.com 4

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Smarty Smarty Presentation Transcript

  • Why use Smarty? PHP is a template engine Separation of logic ◦ Reduced overhead in templating
  • What Smarty is not? NOT an application development framework. NOT an MVC Smarty is the (V)iew component of your application.
  • index.php index.tplinclude(Smarty.class.php); <html>$smarty = new Smarty; <body> User Information:$smarty->assign(name, Name: {$name} „seth‟); Address: {$address} </body>$smarty->assign(address, 45th & Harris); </html>$smarty->display(index.tpl); View slide
  • {assign} index.php$smarty->assign(name, „seth‟);$smarty->assign(address, 45th & Harris); index.tplHi. My name is {$name}.My address is {$address}. View slide
  • {section} index.php$sangam = array(“prabha”,”lakshmi”);$smarty->assign(“sangam”,$sangam); index.tpl{section name=member loop=$sangam} {$sangam[member]}{/section}
  • {foreach} index.php$arr = array(9 => Tennis, 3 => Swimming, 8 => Coding);$smarty->assign(myArray, $arr); index.tpl<ul> {foreach from=$myArray key=k item=v}<li> {$k}: {$v}</li> {/foreach}</ul>
  • {foreach} index.php$arr = array(9 => Tennis, 3 => Swimming, 8 => Coding);$smarty->assign(myArray, $arr); index.tpl<ul> {foreach from=$myArray key=k item=v}<li> {$k}: {$v} <ul></li> <li>9: Tennis</li> {/foreach} <li>3: Swimming</li> <li>8: Coding</li></ul> </ul>
  • {foreach} index.php$smarty->assign(„efforts, array( array( „dev => 1, „mnt => 2, „qa => 3), array( „dev => „4, „mnt => „5, „qa => „6) ));
  • {foreach} index.php {foreach$smarty->assign(„efforts, array( name=outer array( item=effort „dev => 1, from=$efforts} „mnt => 2, {foreach „qa => 3), key=key array( item=item from=$effort} „dev => „4, „mnt => „5, {$key}: {$item} <br/> „qa => „6) {/foreach} )); {/foreach}
  • Qualifier Smarty Syntax PHP Equivalent == $a eq $b == != $a neq $b != > $a gt $b > < $a lt $b < >= $a ge $b >= <= $a le $b <= === $a === 0 === ! not $a ! % $a mod $b %Is [not] divisible by $a is not div by $b $a % $b == 0 Is [not] even $a is not even $a % 2 == 0 Is [not] even by $a is not even by $b ($a/$b)%2==0 Is [not] odd $a is not odd $a % 2 != 0 Is [not] odd by $a is not odd by $b ($a/$b)%2!=0
  • {if}{elseif}{else}{if $name eq Blog} {* do something *}{elseif $name eq $foo} {* do something else *}{/if}{if is_array($foo) and count($foo) > 0} {* do a foreach loop *}{/if}
  • {capture}{capture name=banner} {include file=get_banner.tpl}{/capture}{if $smarty.capture.banner ne } <div id="banner"> {$smarty.capture.banner} </div>{/if}
  • {literal}{literal} <script type="text/javascript"> alert(“Hello World!”); </script>{/literal}{literal} <style type="text/css"> .container{ display:none; } </style>{/literal}
  • {php}{php} global $foo, $bar; if($foo == $bar){ echo This will be sent to browser; } $this->assign(„flavor,„Chocolate);{/php}{$flavor} is my fav ice cream :-)
  • AND We are done…