-
troubleshooting
...Troubleshooting Table of Contents Smarty/PHP errors Smarty/PHP errors Smarty ca...
...s.php on line 1041 Smarty shows you the template name, the line number and the e...
... will see an error similar to the following: Example 20.1. Smarty errors W...
... will see an error similar to the following: Example 20.1. Smarty errors W...
...rrors Warning: Smarty: [in index.tpl line 4]: syntax error: unknown tag - '%blah...
...source.php This means that your application registered a custom error hander (us...
... unable to read resource: "site.conf" in... The $template_dir is incorrect, does...
-
installing.smarty.basic
... Basic Installation Basic Installation basic, installation Basic Installation Pr...
...a trailing slash/ . Here's how you create an instance of Smarty in your PHP scri...
...are in the /libs/ sub directory of the distribution. These are .php files that y...
... all applications and only get changed when you upgrade to a new version of Smar...
...are in the /libs/ sub directory of the distribution. These are .php files that y...
...com/ guestbook/ templates/ index.tpl templates_c/ configs/ cache/ htdocs/ index....
.../ directory. Basically, if your application can find the Smarty.class.php file, ...
-
api.get.tags
... used by template Description string getTags ( object template ); This f...
... getTags() getTags() gettags, getTags() Prev  Chapter 14. Smarty Class...
...= $smarty- createTemplate('index.tpl'); // get tags $tags = $smarty- getTags($tp...
-
language.function.append
...er 7. Built-in Functions  Next {append} {append} is used for creating ...
...lacing application logic into the presentation that may be better handled in PHP...
...yer. See also append() and getTemplateVars() . Prev  Up  Next ChapterÂ...
...lacing application logic into the presentation that may be better handled in PHP...
...a The value being assigned index string No n/a The index for the new array eleme...
...ter handled in PHP. Use at your own discretion. Attributes: Attribute Name Type ...
-
variable.default.resource.type
...ers Home  $default_config_handler_func ...
... smarty what resource type to use implicitly. The default value is file , meanin...
... smarty what resource type to use implicitly. The default value is file , meanin...
...ing that $smarty- display('index.tpl') and $smarty- display('file:index.tpl') ar...
-
language.variables.smarty
...sed to access several environment and request variables. The full list of them f...
...now at start and end will show the three second difference. {* use the date_form...
...arty} variable can be used to access several environment and request variables. ...
...equest variables such as $_GET , $_POST , $_COOKIE , $_SERVER , $_ENV and $_SESS...
...arty} variable can be used to access several environment and request variables. ...
...ET) http://www.example.com/index.php?page=foo *} {$smarty.get.page} {* display t...
-
api.template.exists
...d template exists Description bool templateExists ( string template ); I...
...t can accept either a path to the template on the filesystem or a resource strin...
...ists() This example uses $_GET['page'] to {include} a content template. If the t...
...t can accept either a path to the template on the filesystem or a resource strin...
...php // set the filename eg index.inc.tpl $mid_template = $_GET['page'].'.inc.tpl...
-
language.syntax.functions
... Functions Functions functions Functions Prev  Chapter 3. Basic Syntax...
... built-in functions and custom functions have the same syntax within templates. ...
... built-in functions and custom functions have the same syntax within templates. ...
... . They can be modified to your liking, or you can create new ones. {html_option...
..."banner_ads.tpl" title="My Site"} {if $logged_in} Welcome, span style="color:{#f...
-
smarty.for.designers
...mplate Designers Table of Contents 3. Basic Syntax Comments Variables Functions ...
... @iteration @first @last @show @total {break} {continue} {function} {if},{elseif...
...ng_format strip strip_tags to_charset truncate unescape upper wordwrap 6. Combin...
...ng_format strip strip_tags to_charset truncate unescape upper wordwrap 6. Combin...
...P Associative arrays Array indexes Objects Variable scopes Variables loaded from...
-
language.syntax.variables
...he $dollar sign. They can contain numbers, letters and underscores, much like a ...
...variables are an exception to the $dollar syntax and are instead referenced with...
... find your template syntax getting too complex, it may be a good idea to move th...
...variables are an exception to the $dollar syntax and are instead referenced with...
...ou can reference arrays by index numerically or non-numerically. Also reference ...
... presentation. If you find your template syntax getting too complex, it may be a...
-
api.assign.by.ref
...lues by reference Description void assignByRef ( string varname ,  Â...
...ed var ); This is used to assign() values to the templates by reference. Tec...
... , append() , {assign} and getTemplateVars() . Prev  Up  Next assign()Â...
...ed var ); This is used to assign() values to the templates by reference. Tec...
...ul if you want a PHP array index value to be affected by its reassignment from a...
-
language.variable.scopes
...ate objects you have full control which variables can be seen by a template. Exa...
...scopes You have the choice to assign variables to the scope of the main Smarty o...
...scopes You have the choice to assign variables to the scope of the main Smarty o...
...= $smarty- createTemplate('index.tpl'); $tpl- assign('bar','bar-template'); // a...
-
api.create.template
...a template object Description Smarty_Internal_Template createTemplate ( stri...
...ce instead of passing this to each call to this function. It is used in the even...
...e pairs of variables which get assigned to the object. Example 14.18. crea...
...ce instead of passing this to each call to this function. It is used in the even...
...= $smarty- createTemplate('index.tpl'); // assign variable to template scope $tp...
-
api.append.by.ref
...lues by reference Description void appendByRef ( string varname ,  Â...
... merge ); This is used to append() values to the templates by reference. Tec...
...so append() , assign() and getTemplateVars() . Prev  Up  Next append()Â...
... merge ); This is used to append() values to the templates by reference. Tec...
...ul if you want a PHP array index value to be affected by its reassignment from a...
-
caching
... 15. Caching Table of Contents Setting Up Caching Multiple Caches Per Page C...
...at you are caching and for how long. For instance, if you are displaying the fro...
...Cacheability of Plugins Custom Cache Implementation Caching is used to speed up ...
...ignments here. $contents = get_database_contents(); $smarty- assign($contents); ...
...Cacheability of Plugins Custom Cache Implementation Caching is used to speed up ...
...URRENT); $smarty- display('index.tpl'); ? With caching enabled, the function cal...
...splaying the front page of your website that does not change its content very of...
... the front page of your website that does not change its content very often, it ...
-
language.function.mailto
...pter 8. Custom Functions  Next {mailto} {mailto} automates the creatio...
...ress encode string No none How to encode the e-mail. Can be one of none , hex , ...
... {mailto} {mailto} , ldelim, mailto, rdelim, {mailto} Prev  Chapter 8.Â...
... {mailto} {mailto} , ldelim, mailto, rdelim, {mailto} Prev  Chapter 8.Â...
...t email addresses off of a site. Technical Note Javascript is probably the most ...
-
api.is.cached
...for this template Description bool isCached ( string template ,   ...
...y works if $caching is set to one of Smarty::CACHING_LIFETIME_CURRENT or Smarty:...
...n . Prev  Up  Next getTemplateVars() Home  loadFilter() ...
...y works if $caching is set to one of Smarty::CACHING_LIFETIME_CURRENT or Smarty:...
...T); if(!$smarty- isCached('index.tpl')) { // do database calls, assign vars here...
-
language.builtin.functions
...er 7. Built-in Functions Chapter 7. Built-in Functions chapter, 7, b...
... @iteration @first @last @show @total {break} {continue} {function} {if},{elseif...
...ration @first @last @show @total {break} {continue} {function} {if},{elseif},{el...
...ration @first @last @show @total {break} {continue} {function} {if},{elseif},{el...
...} {foreach},{foreachelse} @index @iteration @first @last @show @total {break} {c...
...ormance. You cannot create your own custom functions with the same name; and you...
-
language.function.html.table
...pter 8. Custom Functions  Next {html_table} {html_table} is a custom f...
... cols attribute determines how many columns will be in the table. The table_attr...
...v  Chapter 8. Custom Functions  Next {html_table} {html_table} is ...
...v  Chapter 8. Custom Functions  Next {html_table} {html_table} is ...
...dd"') ); $smarty- display('index.tpl'); ? The variables assigned from php could ...
-
advanced.features.template.settings
... by template Normally you configure the Smarty settings by modifying the Smarty ...
... global for all templates. However the Smarty class variables and functions can ...
...tions . Modifications done to the Smarty object will be global for all templates...
...tions . Modifications done to the Smarty object will be global for all templates...
...= $smarty- createTemplate('index.tpl); $tpl- cache_lifetime = 600; //or $tpl- se...
-
language.function.foreach
...er 7. Built-in Functions  Next {foreach},{foreachelse} {foreach} is us...
...syntax is new to Smarty 3, however the Smarty 2.x syntax {foreach from=$myarray ...
...ibutes. This syntax is new to Smarty 3, however the Smarty 2.x syntax {foreach f...
...ibutes. This syntax is new to Smarty 3, however the Smarty 2.x syntax {foreach f...
... {foreach} properties are @index , @iteration , @first , @last , @show , @total ...
-
caching.custom
... Custom Cache Implementation Custom Cache Implementation custom, cache, implemen...
... you to store wherever and however you deem fit. The Smarty_CacheResource_KeyVal...
... Custom Cache Implementation Custom Cache Implementation custom, cache, implemen...
...l Resource failed: ' . $e- getMessage()); } $this- fetch = $this- db- prepare('S...
... Custom Cache Implementation Custom Cache Implementation custom, cache, implemen...
...L, * PRIMARY KEY (`id`), * INDEX(`name`), * INDEX(`cache_id`), * INDEX(`compile_...
...ead, write, clear calls to your implementation. This API allows you to store whe...
-
preface
...these goals: clean separation of presentation from application code PHP backend,...
...ion of the Smarty website. How does it work? Under the hood, Smarty "compiles" (...
...d designers quick and easy to maintain syntax easy to understand, no PHP knowled...
...tegration Sometimes Smarty gets compared to Model-View-Controller (MVC) framewor...
...d designers quick and easy to maintain syntax easy to understand, no PHP knowled...
...esentation. Smarty focuses your templates on presentation and less on "code". Th...
...s section of the Smarty website. How does it work? Under the hood, Smarty "compi...
-
advanced.features.outputfilters
...output can be sent through one or more output filters. This differs from postfil...
...ates before they are saved to the disk, whereas output filters operate on the te...
...ates before they are saved to the disk, whereas output filters operate on the te...
...email"); $smarty- display("index.tpl'); // now any occurrence of an email addres...
...filter ?php // put this in your application function protect_email($tpl_output, ...
-
plugins.resources
... sources or PHP script components to Smarty. Some examples of resources: databas...
...s or PHP script components to Smarty. Some examples of resources: databases, LDA...
...ss via $_template- smarty- getTemplateVars() . These Resources simply echo their...
...s or PHP script components to Smarty. Some examples of resources: databases, LDA...
...pt $smarty- display("mysql:index.tpl"); ? And from within Smarty template: {incl...
...ource.foobarxyz.php within your $plugins_dir , or registered on runtime with reg...
-
language.modifier.strip
...the built-in {strip} function. Example 5.19. strip ?php $smarty- assign('a...
...d string. Note If you want to strip blocks of template text, use the built-in {s...
...d string. Note If you want to strip blocks of template text, use the built-in {s...
... one."); $smarty- display('index.tpl'); ? Where template is: {$articleTitle} {$a...
-
caching.cacheable
... Controlling Cacheability of Output Controlling Cacheability of Output controlli...
...t of the page gets cached. However Smarty3 offers several options how to exclude...
...offers several options how to exclude sections of your output from caching. Gene...
...e final output of the page gets cached. However Smarty3 offers several options h...
...offers several options how to exclude sections of your output from caching. Gene...
...); if (!$smarty- isCached('index.tpl')) { // fetch $obj from db and assign... $s...
...how to exclude sections of your output from caching. General Note Be sure any va...
-
what.is.smarty
...e way to separate application logic and content from its presentation. This is b...
...ntain no information about how they will be presented. They are passed into Smar...
...cilitates a manageable way to separate application logic and content from its pr...
...y? Prev  Part I. Getting Started  Next Chapter 1. What is Sm...
...cilitates a manageable way to separate application logic and content from its pr...
...s logic in the template is your own doing. Also, if you desire no logic in your ...
-
caching.groups
...ouping works left-to-right ONLY. You will need to group your templates under a s...
...ouping has no knowledge of how your templates are structured. So for example, if...
...f cache groups like a directory hierarchy. For instance, a cache group of 'a|b|c...
...f cache groups like a directory hierarchy. For instance, a cache group of 'a|b|c...
...structure like themes/blue/index.tpl and you want to be able to clear all the ca...
...LY. You will need to group your templates under a single cache group heirarchy t...
-
language.variables
...4. Variables Table of Contents Variables assigned from PHP Associative array...
...ditional expressions, etc. To print a variable, simply enclose it in the delimit...
...ditional expressions, etc. To print a variable, simply enclose it in the delimit...
...P Associative arrays Array indexes Objects Variable scopes Variables loaded from...
-
advanced.features.postfilters
... postfilters are PHP functions that your templates are ran through after they ar...
...aded from the plugins directory by using the loadFilter() function or by setting...
...aded from the plugins directory by using the loadFilter() function or by setting...
...mment'); $smarty- display('index.tpl'); ? The postfilter above will make the com...
...ers are PHP functions that your templates are ran through after they are compile...
-
api.fetch
...e template output Description string fetch ( string template ,   ...
...in the event that you want to compile different versions of the same template, s...
...t that would automatically get wrapped at 40 characters. This helps make the tex...
...in the event that you want to compile different versions of the same template, s...
... $output = $smarty- fetch('index.tpl', $cache_id); // do something with $output ...
...e link below to login with your user name of '{$contact_info.username}' so you c...
-
api.display
...lays the template Description void display ( string template ,   ...
...he contents of a template. To return the contents of a template into a variable,...
...he contents of a template. To return the contents of a template into a variable,...
...ist if(!$smarty- isCached('index.tpl')) { // dummy up some data $address = '245 ...
-
language.function.assign
...er 7. Built-in Functions  Next {assign} {assign} is used for assigning...
...lacing application logic into the presentation that may be better handled in PHP...
...bles from a php script use getTemplateVars() . Here's the template that creates ...
...lacing application logic into the presentation that may be better handled in PHP...
...ole_page = $smarty- fetch('index.tpl'); // this will output 'smarty' as the temp...
...ter handled in PHP. Use at your own discretion. Note See also the short-form met...
-
caching.multiple.caches
... several different output contents depending on some condition, and you want sep...
...he files for a single call to display() or fetch() . Let's say that a call to di...
...CURRENT); $my_cache_id = $_GET['article_id']; $smarty- display('index.tpl', $my_...
...he files for a single call to display() or fetch() . Let's say that a call to di...
...ay that a call to display('index.tpl') may have several different output content...
... can “ group †your caches together by giving them the same $cache_i...
-
resources.custom
...ting resource plugin functions and registering them with Smarty. See resource pl...
... Custom Template Resources Custom Template Resources custom, template, resources...
...l Resource failed: ' . $e- getMessage()); } $this- fetch = $this- db- prepare('S...
... Custom Template Resources Custom Template Resources custom, template, resources...
...pt $smarty- display("mysql:index.tpl"); ? And from within Smarty template: {incl...
-
plugins.compiler.functions
... Compiler Functions Compiler Functions compiler, functions Compiler Functions Pr...
...sensitive static content into the template. If there is both a compiler function...
...plate as: {* this function gets executed at compile time only *} {tplheader} The...
...sensitive static content into the template. If there is both a compiler function...
...hing like this: ?php echo 'index.tpl compiled at 2002-02-20 20:02'; ? See also r...
-
installing.smarty.extended
...Chapter 2. Installation  Next Extended Setup This is a continuation of...
...slightly more flexible way to setup Smarty is to extend the class and initialize...
...or. // These automatically get set with each new instance. parent::__construct()...
...slightly more flexible way to setup Smarty is to extend the class and initialize...
...; } } ? Now lets alter the index.php file to use setup.php : Example 2.11.Â...
...d the class and initialize your Smarty environment. So instead of repeatedly set...
-
tips.componentized.templates
... Componentized Templates Componentized Templates componentized, templates Compon...
...y, programming templates into your applications goes as follows: First, you accu...
...y, programming templates into your applications goes as follows: First, you accu...
...sign'], $ticker_info); } ? index.tpl {load_ticker symbol='SMARTY' assign='ticker...
...programming templates into your applications goes as follows: First, you accumul...
-
api.register.resource
...egister resources Description void registerResource ( string name ,  ...
...es for more information on how to setup a function for fetching templates. Techn...
...source_handler ); Use this to dynamically register a Resource plugin with Smarty...
...source_handler ); Use this to dynamically register a Resource plugin with Smarty...
...marty- display('c:/path/to/index.tpl'); Note Prior to Smarty 3.1 registerResourc...
-
index
...iling PHP template engine Monte Ohrt monte at ohrt dot com Uwe Tews uwe dot tews...
... @iteration @first @last @show @total {break} {continue} {function} {if},{elseif...
...ng_format strip strip_tags to_charset truncate unescape upper wordwrap 6. Combin...
...ble of Contents Preface I. Getting Started 1. What is Smarty? 2. Installation Re...
...m Uwe Tews uwe dot tews at googlemail dot com Copyright © 2001-2011 New Digit...
...ng_format strip strip_tags to_charset truncate unescape upper wordwrap 6. Combin...
...P Associative arrays Array indexes Objects Variable scopes Variables loaded from...
-
language.function.fetch
...pter 8. Custom Functions  Next {fetch} {fetch} is used to retrieve fil...
...v  Chapter 8. Custom Functions  Next {fetch} {fetch} is used to re...
...v  Chapter 8. Custom Functions  Next {fetch} {fetch} is used to re...
...nclude a trailing slash on your web page fetches where necessary. If the file na...
...ins with http:// , the web site page will be fetched and displayed. Note This wi...
-
advanced.features.objects
...template are for presentation purposes only. It is very easy to inject applicati...
...ain methods or properties. However, a registered object cannot be looped over or...
...jects Smarty allows access to PHP objects through the templates. Note When you a...
... same way custom functions get them. An associative array is passed as the first...
...jects Smarty allows access to PHP objects through the templates. Note When you a...
...$myobj); $smarty- display('index.tpl'); ? And here's how to access your objects ...
...oose will be determined by your needs, but use the first method whenever possibl...
...s section of the Smarty website. There are two ways to access them. One way is t...
-
api.clear.compiled.tpl
... clears the compiled version of the specified template resource Description voi...
... clear entire compile directory $smarty- clearCompiledTemplate(); ? See also cle...
... clear entire compile directory $smarty- clearCompiledTemplate(); ? See also cle...
...ty- clearCompiledTemplate('index.tpl'); // clear entire compile directory $smart...
-
language.function.section
... {section},{sectionelse} {section},{sectionelse} , ldelim, section, rdelim, ldel...
...es the section will loop. show boolean No TRUE Determines whether or not to show...
...ke {foreach} which is used to loop over a single associative array . Every {sect...
...y- assign('contacts', $db- getAll($sql)); ? The template to output the database ...
...ke {foreach} which is used to loop over a single associative array . Every {sect...
... looping over sequentially indexed arrays of data , unlike {foreach} which is us...
-
resources
...16. Resources Table of Contents File Template Resources Templates from $templ...
...ir Templates from any directory Windows Filepaths String Template Resources Stre...
...id namespace conflicts and get the desired results. Example 16.4. Using te...
...ir Templates from any directory Windows Filepaths String Template Resources Stre...
...dir ?php $smarty- display('index.tpl'); $smarty- display('file:index.tpl'); // s...
...plate_dir . This allows websites employing multiple sets of templates better con...
-
api.create.data
...tes a data object Description string createData ( object parent ); strin...
...parameter. It is an uplink to the main Smarty object, a another user-created dat...
...parameter. It is an uplink to the main Smarty object, a another user-created dat...
...= $smarty- createTemplate('index.tpl',$data); // display the template $tpl- disp...
-
api.clear.cache
...specific template Description void clearCache ( string template ,  Â...
...r. You can group templates together so they can be removed as a group, see the c...
... You can group templates together so they can be removed as a group, see the cac...
...r. You can group templates together so they can be removed as a group, see the c...
...plate $smarty- clearCache('index.tpl'); // clear the cache for a particular cach...
-
advanced.features.prefilters
...e prefilters are PHP functions that your templates are ran through before they a...
...eprocessing your templates to remove unwanted comments, keeping an eye on what p...
...eprocessing your templates to remove unwanted comments, keeping an eye on what p...
...ments'); $smarty- display('index.tpl'); ? See also registerFilter() , postfilter...
...ers are PHP functions that your templates are ran through before they are compil...