Tecnología
Initializing Smarty
include(”smarty/Smarty.class.php”); $smarty = new smarty();
Hasin Hayder Zend Certified Engineer http://hasin.wordpress.com
Loop{section name=id loop=$variable} element : {$variable[id]} {sectionelse} If supplied variable is empty, you’ll see it {/section} {foreach item=curItem from=$items} element : {$curItem} {foreachelse} Ifsupplied variable is empty, you’ll see it {/foreach}
Logic
{if $var == condition} something to do {elseif $var == condition} something to do {else} something else to do {/if }
| | | | | | | | |Directory Structure
your_script_folder - smarty | - libs | | Smarty.class.php - templates | greet.tpl + templates_c [atleast 0665] + configs my_other_scripts.php blah_blah_script.php
AssigningVariables
General Format $smarty->assign(”var”,”value”); Example $smarty->assign(”who”, “world”);
Sample Template
Filename : templates\greet.tpl Hello {$who}
Processing Objects
Access ObjectMethods {$object->method param1=”val” param2=”val”} Accesing Object Properties {$object->property} Assign method output to variable {$object->method param1=”val” param2=”val”} assign=”storage_var”}Output: {$storage_var}
Display Output
$smarty->display(”greet.tpl”);
Common Modifiers
capitalize, count_characters, cat, count_paragraphs, count_sentences,count_words, date_format, default,escape, indent, lower, nl2br, regex_replace, replace, spacify, string_format, strip, strip_tags, truncate, upper, wordwrap
Debugging templates
Add this line at the top {debug}
Capturing output inphp variable
Use Fetch() function $output = $smarty->fetch(”greet.tpl”); echo $output;
Builtin Functions
capture, config_load, foreach, foreachelse, include, include_php, insert if, elseif, else,ldelim, rdelim, literal, php, section, sectionelse, strip
Passing objects to template
$my_class=new my_object(); $smarty->register_object( “object”, $my_class);
Processing indexed array...
Regístrate para leer el documento completo.