phpSmartyCheatSheet.PDF
(
174 KB
)
Pobierz
SmartyCheetSheat copy
Smarty Cheat Sheet for Template Designers
Hasin Hayder
http://hasin.wordpress.com
hasin@somewherein.net
Initializing Smarty
Loop
Logic
Directory Structure
include(”smarty/Smarty.class.php”);
$smarty = new smarty();
{section name=id loop=$variable}
element : {$variable[id]}
{/section}
{if $var == condition}
something to do
{elseif $var == condition}
something to do
{else}
something else to do
{/if }
- your_script_folder
| - smarty
| | + libs
| | Smarty.class.php
| - templates
| | greet.tpl
| + templates_c
[must be 0777]
| + configs
| my_other_scripts.php
| blah_blah_script.php
Assigning Variables
General Format
$smarty->assign(”var”,”value”);
Example
$smarty->assign(”who”, “world”);
{foreach item=curItem from=$items}
element : {$curItem}
{/foreach}
Sample Template
Processing objects
Common Modifiers
Filename : templates\greet.tpl
Hello {$who}
Access Object Methods
{object->method
param1=”val”
param2=”val”}
Display Output
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
$smarty->display(”greet.tpl”);
Accesing Object Properties
{object->property}
Debugging templates
Assign method output to variable
{object->method
param1=”val”
param2=”val”}
assign=”storage_var”}
Add this line at the top
{debug}
Builtin Functions
Capturing output in php variable
capture, config_load, foreach, foreachelse, include, include_php, insert
if, elseif, else, ldelim, rdelim, literal, php, section, sectionelse, strip
Use Fetch() function
$output =
$smarty->fetch(”greet.tpl”);
echo $output;
Output: {$storage_var}
Custom Functions
Passing objects to template
$my_class=new my_object();
$smarty->register_object(
“object”, $my_class);
Processing indexed array
assign, counter, cycle, debug, eval, fetch, html_checkboxes, html_image
html_options, html_radios, html_select_date, html_select_time
html_table, math, mailto, popup_init, popup, textformat
{section name=id loop=$array}
Current Item : {$array[id]}<br/>
{/section}
Using modifiers
General Format
{$variable | modifier:parameter}
Example
{$name|count_characters}
Processing associated array
Smarty reserved variables
$smarty.now
$smarty.const
$smarty.capture
$smarty.config
$smarty.section
$smarty.foreach
$smarty.template
$smarty.version
$smarty.ldelim
$smarty.rdelim
{student.name}
{student.roll}
{$student.age}
$smarty.get
$smarty.post
$smarty.session
$smarty.session
$smarty.env
$smarty.request
$smarty.env
Execute PHP inside template
Passing associated array
{php}
for($i=0;$i<10;$i++)
echo “Hello”;
{/php}
$student=array(”name”=>”shumi”);
$smarty->assign(”student”,$std);
Smarty website : http://smarty.php.net
Icon Courtesy : Tango Project (http://tango-project.org)
Smarty Book : http://packtpub.com/smarty/book
Plik z chomika:
macDriper
Inne pliki z tego folderu:
sql reference.pdf
(4866 KB)
ruby-on-rails-cheat-sheet-v1.pdf
(752 KB)
qrg0007.pdf
(92 KB)
phpSmartyCheatSheet.PDF
(174 KB)
mootools-12-cheat-sheet-pf.pdf
(80 KB)
Inne foldery tego chomika:
biznes
blogowanie
chemia
fizyka
matma
Zgłoś jeśli
naruszono regulamin