-
installing.smarty.basic
...are in the /libs/ sub directory of the distribution. These are .php files that y...
...Basic Installation Install the Smarty library files which are in the /libs/ sub ...
...com/ guestbook/ templates/ index.tpl templates_c/ configs/ cache/ htdocs/ index....
... Basic Installation Basic Installation basic, installation Basic Installation Pr...
-
api.get.tags
...pairs for all tags used by the template. It uses the following parameters: templ...
...= $smarty- createTemplate('index.tpl'); // get tags $tags = $smarty- getTags($tp...
... used by template Description string getTags ( object template ); This f...
-
language.function.append
...lacing application logic into the presentation that may be better handled in PHP...
...ate variable arrays during the execution of a template . Note Assignment of vari...
...a The value being assigned index string No n/a The index for the new array eleme...
...er 7. Built-in Functions  Next {append} {append} is used for creating ...
-
variable.default.resource.type
... smarty what resource type to use implicitly. The default value is file , meanin...
...ce type to use implicitly. The default value is file , meaning that $smarty- dis...
...ing that $smarty- display('index.tpl') and $smarty- display('file:index.tpl') ar...
...ers Home  $default_config_handler_func ...
-
language.variables.smarty
...arty} variable can be used to access several environment and request variables. ...
..., etc. Note The {$smarty.foreach} variable is no longer used with the new {forea...
...$smarty} reserved variable The PHP reserved {$smarty} variable can be used to ac...
...lue reflects the number of seconds passed since the so-called Epoch on January 1...
...ET) http://www.example.com/index.php?page=foo *} {$smarty.get.page} {* display t...
...sed to access several environment and request variables. The full list of them f...
-
api.template.exists
...t can accept either a path to the template on the filesystem or a resource strin...
...xists() — checks whether the specified template exists Description boolÂ...
...php // set the filename eg index.inc.tpl $mid_template = $_GET['page'].'.inc.tpl...
...d template exists Description bool templateExists ( string template ); I...
-
smarty.for.designers
...ng_format strip strip_tags to_charset truncate unescape upper wordwrap 6. Combin...
...{debug} {extends} {for} {foreach},{foreachelse} @index @iteration @first @last @...
...P Associative arrays Array indexes Objects Variable scopes Variables loaded from...
...mplate Designers Table of Contents 3. Basic Syntax Comments Variables Functions ...
-
language.syntax.variables
...variables are an exception to the $dollar syntax and are instead referenced with...
...plate variables start with the $dollar sign. They can contain numbers, letters a...
...ou can reference arrays by index numerically or non-numerically. Also reference ...
...he $dollar sign. They can contain numbers, letters and underscores, much like a ...
-
api.assign.by.ref
...ed var ); This is used to assign() values to the templates by reference. Tec...
...used to assign() values to the templates by reference. Technical Note With the i...
...ul if you want a PHP array index value to be affected by its reassignment from a...
...lues by reference Description void assignByRef ( string varname ,  Â...
-
language.variable.scopes
...scopes You have the choice to assign variables to the scope of the main Smarty o...
...t Variable scopes You have the choice to assign variables to the scope of the ma...
...= $smarty- createTemplate('index.tpl'); $tpl- assign('bar','bar-template'); // a...
...ate objects you have full control which variables can be seen by a template. Exa...
-
api.create.template
...ce instead of passing this to each call to this function. It is used in the even...
...h later can be rendered by the display or fetch method. It uses the following pa...
...= $smarty- createTemplate('index.tpl'); // assign variable to template scope $tp...
...a template object Description Smarty_Internal_Template createTemplate ( stri...
-
api.append.by.ref
... merge ); This is used to append() values to the templates by reference. Tec...
...used to append() values to the templates by reference. Technical Note With the i...
...ul if you want a PHP array index value to be affected by its reassignment from a...
...lues by reference Description void appendByRef ( string varname ,  Â...
-
caching
...Cacheability of Plugins Custom Cache Implementation Caching is used to speed up ...
...le. If a cached version of the call is available, that is displayed instead of r...
...determine // the number of seconds a cache is good for $smarty- setCaching(Smart...
...URRENT); $smarty- display('index.tpl'); ? With caching enabled, the function cal...
... 15. Caching Table of Contents Setting Up Caching Multiple Caches Per Page C...
-
api.is.cached
...y works if $caching is set to one of Smarty::CACHING_LIFETIME_CURRENT or Smarty:...
...) — returns true if there is a valid cache for this template Description ...
...a $cache_id as an optional second parameter in case you want multiple caches for...
...T); if(!$smarty- isCached('index.tpl')) { // do database calls, assign vars here...
...for this template Description bool isCached ( string template ,   ...
-
language.builtin.functions
...ration @first @last @show @total {break} {continue} {function} {if},{elseif},{el...
...{debug} {extends} {for} {foreach},{foreachelse} @index @iteration @first @last @...
...everal built-in functions. These built-in functions are the integral part of the...
...} {foreach},{foreachelse} @index @iteration @first @last @show @total {break} {c...
...er 7. Built-in Functions Chapter 7. Built-in Functions chapter, 7, b...
-
language.function.html.table
...v  Chapter 8. Custom Functions  Next {html_table} {html_table} is ...
... No 3 Number of columns in the table or a comma-separated list of column heading...
...ble loop=$data cols="first,second,third,fourth" tr_attr=$tr} table border="1" th...
...dd"') ); $smarty- display('index.tpl'); ? The variables assigned from php could ...
...pter 8. Custom Functions  Next {html_table} {html_table} is a custom f...
-
advanced.features.template.settings
...tions . Modifications done to the Smarty object will be global for all templates...
...ate Normally you configure the Smarty settings by modifying the Smarty class var...
...= $smarty- createTemplate('index.tpl); $tpl- cache_lifetime = 600; //or $tpl- se...
... by template Normally you configure the Smarty settings by modifying the Smarty ...
-
language.function.foreach
...ibutes. This syntax is new to Smarty 3, however the Smarty 2.x syntax {foreach f...
... {foreach},{foreachelse} {foreach},{foreachelse} , ldelim, foreach, rdelim, ldel...
...er and cleaner syntax than the {section} loop, and can also loop over associativ...
... {foreach} properties are @index , @iteration , @first , @last , @show , @total ...
...er 7. Built-in Functions  Next {foreach},{foreachelse} {foreach} is us...
-
caching.custom
... Custom Cache Implementation Custom Cache Implementation custom, cache, implemen...
...eys = $lookup = array(); foreach ($keys as $k) { $_k = sha1($k); $_keys[] = $_k;...
...As an alternative to using the default file-based caching mechanism, you can spe...
...ram integer|null $exp_time seconds till expiration time in seconds or null * @pa...
...L, * PRIMARY KEY (`id`), * INDEX(`name`), * INDEX(`cache_id`), * INDEX(`compile_...
... Custom Cache Implementation Custom Cache Implementation custom, cache, implemen...
-
troubleshooting
... will see an error similar to the following: Example 20.1. Smarty errors W...
...ll see an error similar to the following: Example 20.1. Smarty errors Warn...
...rrors Warning: Smarty: [in index.tpl line 4]: syntax error: unknown tag - '%blah...
...Troubleshooting Table of Contents Smarty/PHP errors Smarty/PHP errors Smarty ca...
-
advanced.features.outputfilters
...ates before they are saved to the disk, whereas output filters operate on the te...
... Next Output Filters When the template is invoked via display() or fetch() , it...
...email"); $smarty- display("index.tpl'); // now any occurrence of an email addres...
...output can be sent through one or more output filters. This differs from postfil...
-
plugins.resources
...s or PHP script components to Smarty. Some examples of resources: databases, LDA...
... registerResource() . In either case you will be able to access that resource by...
...pt $smarty- display("mysql:index.tpl"); ? And from within Smarty template: {incl...
... sources or PHP script components to Smarty. Some examples of resources: databas...
-
language.modifier.strip
...d string. Note If you want to strip blocks of template text, use the built-in {s...
...th a single space, or with the supplied string. Note If you want to strip blocks...
... one."); $smarty- display('index.tpl'); ? Where template is: {$articleTitle} {$a...
...the built-in {strip} function. Example 5.19. strip ?php $smarty- assign('a...
-
caching.cacheable
...offers several options how to exclude sections of your output from caching. Gene...
...ill the endtime of $obj is reached changes on each display of the page, even if ...
...aching is enabled normally the whole final output of the page gets cached. Howev...
...RRENT); function remaining_seconds($params, $smarty) { $remain = $params['endtim...
...); if (!$smarty- isCached('index.tpl')) { // fetch $obj from db and assign... $s...
... Controlling Cacheability of Output Controlling Cacheability of Output controlli...
-
caching.groups
...f cache groups like a directory hierarchy. For instance, a cache group of 'a|b|c...
...p with a vertical bar | in the $cache_id value. You can have as many sub-groups ...
...structure like themes/blue/index.tpl and you want to be able to clear all the ca...
...ouping works left-to-right ONLY. You will need to group your templates under a s...
-
language.variables
...ditional expressions, etc. To print a variable, simply enclose it in the delimit...
...ferent types of variables. The type of the variable depends on what symbol it is...
...P Associative arrays Array indexes Objects Variable scopes Variables loaded from...
...4. Variables Table of Contents Variables assigned from PHP Associative array...
-
advanced.features.postfilters
...aded from the plugins directory by using the loadFilter() function or by setting...
...ates are ran through after they are compiled . Postfilters can be either registe...
...mment'); $smarty- display('index.tpl'); ? The postfilter above will make the com...
... postfilters are PHP functions that your templates are ran through after they ar...
-
api.fetch
...in the event that you want to compile different versions of the same template, s...
...e fetch() — returns the template output Description string fetch ( st...
...e and path. As an optional second parameter, you can pass a $cache id , see the ...
... $output = $smarty- fetch('index.tpl', $cache_id); // do something with $output ...
...e template output Description string fetch ( string template ,   ...
-
api.display
...he contents of a template. To return the contents of a template into a variable,...
...isplay() — displays the template Description void display ( stringÂ...
...e and path. As an optional second parameter, you can pass a $cache_id , see the ...
...ist if(!$smarty- isCached('index.tpl')) { // dummy up some data $address = '245 ...
...lays the template Description void display ( string template ,   ...
-
language.function.assign
...lacing application logic into the presentation that may be better handled in PHP...
... template variables during the execution of a template . Note Assignment of vari...
...ole_page = $smarty- fetch('index.tpl'); // this will output 'smarty' as the temp...
...er 7. Built-in Functions  Next {assign} {assign} is used for assigning...
-
caching.multiple.caches
...he files for a single call to display() or fetch() . Let's say that a call to di...
... by passing a $cache_id as the second parameter to the function call. ExampleÂ...
...passing a $cache_id as the second parameter to the function call. Example 15....
...ay that a call to display('index.tpl') may have several different output content...
... several different output contents depending on some condition, and you want sep...
-
resources.custom
... Custom Template Resources Custom Template Resources custom, template, resources...
... functions and registering them with Smarty. See resource plugins section for mo...
...pt $smarty- display("mysql:index.tpl"); ? And from within Smarty template: {incl...
...ting resource plugin functions and registering them with Smarty. See resource pl...
-
plugins.compiler.functions
...sensitive static content into the template. If there is both a compiler function...
...only during compilation of the template. They are useful for injecting PHP code ...
...hing like this: ?php echo 'index.tpl compiled at 2002-02-20 20:02'; ? See also r...
... Compiler Functions Compiler Functions compiler, functions Compiler Functions Pr...
-
installing.smarty.extended
...slightly more flexible way to setup Smarty is to extend the class and initialize...
... This is a continuation of the basic installation , please read that first! A sl...
...; } } ? Now lets alter the index.php file to use setup.php : Example 2.11.Â...
...Chapter 2. Installation  Next Extended Setup This is a continuation of...
-
tips.componentized.templates
...y, programming templates into your applications goes as follows: First, you accu...
...be with database queries.) Then, you instantiate your Smarty object, assign() th...
...sign'], $ticker_info); } ? index.tpl {load_ticker symbol='SMARTY' assign='ticker...
... Componentized Templates Componentized Templates componentized, templates Compon...
-
api.register.resource
...source_handler ); Use this to dynamically register a Resource plugin with Smarty...
...lugin with Smarty. Pass in the name of the Resource and the object extending Sma...
...marty- display('c:/path/to/index.tpl'); Note Prior to Smarty 3.1 registerResourc...
...egister resources Description void registerResource ( string name ,  ...
-
index
...ng_format strip strip_tags to_charset truncate unescape upper wordwrap 6. Combin...
...{debug} {extends} {for} {foreach},{foreachelse} @index @iteration @first @last @...
... Â Â Next Smarty - the compiling PHP template engine Monte Ohrt monte at...
...xample 8.14. {html_radios} second example 8.15. {html_radios} - Database example...
...P Associative arrays Array indexes Objects Variable scopes Variables loaded from...
...iling PHP template engine Monte Ohrt monte at ohrt dot com Uwe Tews uwe dot tews...
-
advanced.features.objects
...jects Smarty allows access to PHP objects through the templates. Note When you a...
...ess to PHP objects through the templates. Note When you assign/register objects ...
...d the smarty object as the second. If you want the parameters passed one at a ti...
...$myobj); $smarty- display('index.tpl'); ? And here's how to access your objects ...
...template are for presentation purposes only. It is very easy to inject applicati...
-
api.clear.compiled.tpl
... clear entire compile directory $smarty- clearCompiledTemplate(); ? See also cle...
...Template() — clears the compiled version of the specified template resour...
...plates older than exp_time seconds are cleared, by default all compiled template...
...ty- clearCompiledTemplate('index.tpl'); // clear entire compile directory $smart...
... clears the compiled version of the specified template resource Description voi...
-
language.function.section
...ke {foreach} which is used to loop over a single associative array . Every {sect...
...arrays of data , unlike {foreach} which is used to loop over a single associativ...
...osing {/section} tag. Note The {foreach} loop can do everything a {section} loop...
... looping over sequentially indexed arrays of data , unlike {foreach} which is us...
... {section},{sectionelse} {section},{sectionelse} , ldelim, section, rdelim, ldel...
-
resources
...ir Templates from any directory Windows Filepaths String Template Resources Stre...
... Custom Template Resources The templates may come from a variety of sources. Whe...
...dir ?php $smarty- display('index.tpl'); $smarty- display('file:index.tpl'); // s...
...16. Resources Table of Contents File Template Resources Templates from $templ...
-
api.create.data
...parameter. It is an uplink to the main Smarty object, a another user-created dat...
...ssigned variables. It uses the following parameters: parent is an optional param...
...= $smarty- createTemplate('index.tpl',$data); // display the template $tpl- disp...
...tes a data object Description string createData ( object parent ); strin...
-
api.clear.cache
...r. You can group templates together so they can be removed as a group, see the c...
...earCache() — clears the cache for a specific template Description voidÂ...
...plying the cache_id as the second parameter. You can also pass a $compile_id as ...
...plate $smarty- clearCache('index.tpl'); // clear the cache for a particular cach...
...specific template Description void clearCache ( string template ,  Â...
-
advanced.features.prefilters
...eprocessing your templates to remove unwanted comments, keeping an eye on what p...
...tes are ran through before they are compiled . This is good for preprocessing yo...
...ments'); $smarty- display('index.tpl'); ? See also registerFilter() , postfilter...
...e prefilters are PHP functions that your templates are ran through before they a...