Hubwiz.com
|
Online Course
|
API Manual
Smarty API Manual
Guide(48)
Variable(55)
Operator(24)
Function(38)
Constant(1)
Method(53)
Sample(276)
Guide
What is Smarty?
Requirements
Basic Installation
Extended Setup
Comments
Variables
Functions
Attributes
Embedding Vars in Double Quotes
Math
Escaping Smarty Parsing
Variable scopes
Variables loaded from config files
Associative arrays
Array indexes
Objects
Charset Encoding
Setting Up Caching
Multiple Caches Per Page
Cache Groups
Custom Cache Implementation
Cacheability of Template Section
Cacheability of Tags
Cacheability of Variables
Cacheability of Plugins
String Template Resources
Stream Template Resources
Extends Template Resources
Custom Template Resources
Templates from $template_dir
Templates from a specific $template_dir
Templates from any directory
Windows Filepaths
How Plugins Work
Naming Conventions
Writing Plugins
Template Functions
Modifiers
Block Functions
Compiler Functions
Prefilters/Postfilters
Output Filters
Resources
Inserts
SmartyBC class
Smarty/PHP errors
Resources
BUGS
Variable
{$smarty.now}
{$smarty.const}
{$smarty.capture}
{$smarty.config}
{$smarty.section}
{$smarty.template}
{$smarty.template_object}
{$smarty.current_dir}
{$smarty.version}
{$smarty.block.child}
{$smarty.block.parent}
{$smarty.ldelim}, {$smarty.rdelim}
Smarty->$allow_php_templates
Smarty->$auto_literal
Smarty->$autoload_filters
Smarty->$cache_dir
Smarty->$cache_id
Smarty->$cache_lifetime
Smarty->$cache_locking
Smarty->$cache_modified_check
Smarty->$caching
Smarty->$caching_type
Smarty->$compile_check
Smarty->$compile_dir
Smarty->$compile_id
Smarty->$compile_locking
Smarty->$compiler_class
Smarty->$config_booleanize
Smarty->$config_dir
Smarty->$config_overwrite
Smarty->$config_read_hidden
Smarty->$debug_tpl
Smarty->$debugging
Smarty->$debugging_ctrl
Smarty->$default_config_type
Smarty->$default_modifiers
Smarty->$default_resource_type
Smarty->$default_config_handler_func
Smarty->$default_template_handler_func
Smarty->$direct_access_security
Smarty->$error_reporting
Smarty->$escape_html
Smarty->$force_cache
Smarty->$force_compile
Smarty->$left_delimiter
Smarty->$locking_timeout
Smarty->$merge_compiled_includes
Smarty->$php_handling
Smarty->$plugins_dir
Smarty->$right_delimiter
Smarty->$smarty_debug_id
Smarty->$template_dir
Smarty->$trusted_dir
Smarty->$use_include_path
Smarty->$use_sub_dirs
Operator
capitalize
cat
count_characters
count_paragraphs
count_sentences
count_words
date_format
default
escape
from_charset
indent
lower
nl2br
regex_replace
replace
spacify
string_format
strip
strip_tags
to_charset
truncate
unescape
upper
wordwrap
Function
{$var=...}
{append}
{assign}
{block}
{call}
{capture}
{config_load}
{debug}
{extends}
{for}
{foreach},{foreachelse}
{function}
{if},{elseif},{else}
{include}
{include_php}
{insert}
{ldelim},{rdelim}
{literal}
{nocache}
{php}
{section},{sectionelse}
{setfilter}
{strip}
{while}
{counter}
{cycle}
{eval}
{fetch}
{html_checkboxes}
{html_image}
{html_options}
{html_radios}
{html_select_date}
{html_select_time}
{html_table}
{mailto}
{math}
{textformat}
Constant
SMARTY_DIR
Method
Smarty->addConfigDir()
Smarty->addPluginsDir()
Smarty->addTemplateDir()
Smarty->append()
Smarty->appendByRef()
Smarty->assign()
Smarty->assignByRef()
Smarty->clearAllAssign()
Smarty->clearAllCache()
Smarty->clearAssign()
Smarty->clearCache()
Smarty->clearCompiledTemplate()
Smarty->clearConfig()
Smarty->compileAllConfig()
Smarty->compileAllTemplates()
Smarty->configLoad()
Smarty->createData()
Smarty->createTemplate()
Smarty->disableSecurity()
Smarty->display()
Smarty->enableSecurity()
Smarty->fetch()
Smarty->getCacheDir()
Smarty->getCompileDir()
Smarty->getConfigDir()
Smarty->getConfigVars()
Smarty->getPluginsDir()
Smarty->getRegisteredObject()
Smarty->getTags()
Smarty->getTemplateDir()
Smarty->getTemplateVars()
Smarty->isCached()
Smarty->loadFilter()
Smarty::muteExpectedErrors()
Smarty->registerCacheResource()
Smarty->registerClass()
Smarty->registerDefaultPluginHandler()
Smarty->registerFilter()
Smarty->registerPlugin()
Smarty->registerObject()
Smarty->registerResource()
Smarty->setCacheDir()
Smarty->setCompileDir()
Smarty->setConfigDir()
Smarty->setPluginsDir()
Smarty->setTemplateDir()
Smarty->templateExists()
Smarty->unregisterCacheResource()
Smarty->unregisterFilter()
Smarty->unregisterPlugin
Smarty->unregisterObject()
Smarty->unregisterResource()
Smarty->testInstall()
Sample
Required Smarty library files
Set SMARTY_DIR constant manually
Supply absolute path to library file
Add the library path to the php.ini file
Appending the include path in a php script with ini_set()
What the file structure looks like
Permissions and making directories writable
/web/www.example.com/guestbook/templates/index.tpl
Editing /web/www.example.com/docs/guestbook/index.php
/php/includes/guestbook/setup.php
/web/www.example.com/guestbook/htdocs/index.php
Comments within a template
Variables
function syntax
function attribute syntax
Syntax examples
Examples
math examples
Using the auto-literal feature
changing delimiters example
Example variables
Assigned variables
Accessing associative array variables
Accessing arrays by index
Accessing object properties
Variable scope examples
config variables
Displaying request variables
Modifier examples
capitalize
cat
count_characters
count_paragraphs
count_sentences
count_words
date_format
default
escape
Other examples
indent
lower
nl2br
regex_replace
replace
spacify
string_format
strip
strip_tags
truncate
escape
upper
wordwrap
combining modifiers
Simple assignment
Assignment with math
Assignment of an array element
Assignment of an multidimensional array element
Appending an array
Assigment in the scope of calling template
{append}
{assign}
{assign} as a nocache variable
{assign} with some maths
{assign} in the scope of calling template
{assign} a variable to current scope tree
{assign} a global variable
Accessing {assign} variables from a PHP script
Simple {block} example
Prepend {block} example
Append {block} example
{$smarty.block.child} example
{$smarty.block.parent} example
Calling a recursive menu example
{capture} with the name attribute
{capture} into a template variable
{capture} into a template array variable
{config_load}
function {config_load} with section
Simple {extends} example
A simple {for} loop
Using the max attribute
Excution of {forelse}
A simple {foreach} loop
Demonstrates the an additional key variable
{foreach} with nested item and key
Database example with {foreachelse}
index example
iteration example: is div by
iteration example: is even/odd by
first property example
last property example
show property example
total property example
{break} example
{continue} example
Recursive menu {function} example
{if} statements
{if} with more examples
Simple {include} example
{include} passing variables
{include} using parent scope
{include} with disabled caching
{include} with individual cache lifetime
{include} with forced caching
{include} and assign to variable
{include} with relative paths
Various {include} resource examples
function {include_php}
function {insert}
{ldelim}, {rdelim}
Another Javascript example
{literal} tags
Preventing a template section from being cached
php code within {php} tags
{php} tags with global and assigning a variable
Looping a simple array with {section}
{section} without an assigned array
Naming a {section}
Looping an associative array with {section}
{section} demonstrating the loop variable
Nested {section}'s
Database example with a {sectionelse}
{section} index property
index, index_next and index_prev properties
A section's iteration property
{section} property first and last
{section} property loop
show property
total property example
{setfilter} tags
{strip} tags
{while} loop
{counter}
{cycle}
{eval}
Another {eval} example
{fetch} examples
{html_checkboxes}
Database example (eg PEAR or ADODB):
{html_image} example
Associative array with the options attribute
Dropdown with separate arrays for values and ouptut
Database example (eg ADODB or PEAR)
Dropdown's with <optgroup>
{html_radios} first example
{html_radios} second example
{html_radios} - Database example (eg PEAR or ADODB):
{html_select_date}
{html_select_date} second example
{html_select_time}
{html_table}
{mailto} example lines followed by the result
{math}
{textformat}
Example of config file syntax
Setting a different Charset Encoding
SMARTY_DIR
$compile_id in a virtual host environment
Array of config #variables#
$debugging_ctrl on localhost
$default_config_handler_func
$default_template_handler_func
addConfigDir()
addPluginsDir()
addTemplateDir()
append
appendByRef
assign()
assignByRef()
clearAllAssign()
clearAllCache
clearAssign()
clearCache()
clearCompiledTemplate()
clearConfig()
compileAllConfig()
compileAllTemplates()
configLoad()
createData()
createTemplate()
display()
Other display() template resource examples
fetch()
Using fetch() to send an email
getCacheDir()
getCompileDir()
getConfigDir()
getConfigVars()
getPluginsDir()
getRegisteredObject()
getTags()
getTemplateDir()
getTemplateVars
isCached()
isCached() with multiple-cache template
Loading filter plugins
registerCacheResource()
Register class for use within a template
Register namespaced class for use within a template
Default Plugin Handler Example
register a function plugin
register block function plugin
register modifier plugin
registerResource()
setCacheDir()
setCompileDir()
setConfigDir()
setPluginsDir()
setTemplateDir()
templateExists()
unregisterCacheResource()
unregister function plugin
unregisterResource()
testInstall()
Enabling caching
Setting $cache_lifetime per cache
Disabling $compile_check
Using isCached()
Clearing the cache
Passing a $cache_id to display()
Passing a cache_id to isCached()
Clearing all caches for a particular $cache_id
$cache_id groups
Preventing a template section from being cached
Preventing tag output from being cached
Nocache Variables
Preventing a plugin's output from being cached
Preventing a whole passage of a template from being cached
Smarty_CacheResource_Mysql
Smarty_CacheResource_Memcache
Using templates from the $template_dir
Specifying the $template_dir to use
Using templates from any directory
Using templates from windows file paths
Using templates from strings
Using templates from encoded strings
Stream from PHP
Stream from Template
Using template inheritance from the PHP script
Using custom resources
Setting security policy by extending the Smarty_Security class
Setting security policy by instance of the Smarty_Security class
Enable security with the default settings
changing Smarty settings by template
register plugins by template
Template inheritance example
Template inheritance by template resource extends:
Stream Variable
Using a registered or assigned object
static class access syntax
Using a template prefilter
Using a template postfilter
Using a template outputfilter
function plugin with output
function plugin without output
A simple modifier plugin
More complex modifier plugin
block function
A simple compiler function
prefilter plugin
postfilter plugin
An output filter plugin
Using custom resources
insert plugin
Using SmartyBC
Smarty errors
PHP parsing errors
Other common errors
Printing &nbsp; when a variable is empty
Assigning a template variable its default value
Passing the title variable to the header template
Using date_format
Converting form date elements back to a timestamp
Using {insert} to write a WML Content-Type header
componentized template
Example of template the Obfuscating an email address