Overview
KB
Learn PHP
PHP techniques
PHP Smarty Functions
PHP Web Email
Secure development
PHP Security Scenario
SSH and SFTP
PHP Smarty
PHP Smarty Modifiers
PHP Smarty Caching
PHP Smarty Misc
CakePHP
Zend Framework
PHP basics

PHP Smarty Miscellaneous

The $smarty Reserved Variable

Smarty has one special variable, $smarty, for accessing configuration variables, PHP's superglobals, and so on. To access a Superglobal through $smarty, use $smarty.superglobal_name.key. For example, a page_id value passed in the URL would be accessible in $smarty.get.page_id and $_SESSION['name'] can be accessed as $smarty.session.name. Constants in PHP code are available through $smarty.const. The syntax is similar to that of accessing Superglobals: $smarty.const.CONSTANT_NAME.
Smarty code in NuSphere's PhpED - smarty call php function
$smarty.now represents the current timestamp, useful in formatting dates. (The sample Smarty template that NuSphere's PhpED uses makes reference to this variable, see the image>) Configuration variables (see below) are accessible through $smarty.config. The current template value is stored in $smarty.template (this can be useful for debugging). The current version of Smarty is stored in $smarty.version. A couple of functions make use of $smarty, as well. The "section" and "foreach" loops can use $smarty.section and $smarty.foreach.

Configuration Files

Smarty supports application configuration files, where you can store useful values that the templates may require. A configuration file is a plain text file, normally given a .conf extension. Within the file, use a name=value syntax:
some_thing = "This value" 
default_color = "#FFFFFF"
Note that this is not PHP code, so the names do not start with a dollar sign and the lines do not end with semicolons. You do not even have to quote the values, although doing so makes stylistic sense. Comments can be placed within a configuration file using almost any syntax, but the recommendation is to precede the comment with the hash:
# this is a comment.
Configuration files can be broken into sections, identified by a name within square brackets:
some_thing = "This value" 
default_color = "#FFFFFF"     

[some_section] 
some_other_thing = "some other value"
Values defined outside of a section are considered global. This distinction is relevant when loading configuration files in a template. If the same name is given the same value globally and within a section, the section value will overwrite the global one. Configuration files can be loaded into a template using the "config_load" function:
{config_load file='somefile.conf'}
To load only a specific section of the config file, follow the configuration file name with the section:
{config_load file='somefile.conf' section='some_section'}
When only a section of a configuration file is loaded, that section's variables are loaded, as well as any global variables. Alternatively, you can load a configuration file using the config_load() method:
require('Smarty.class.php'); 
$page = new Smarty(); 
$page->config_load('somefile.conf'); 
$page->config_load('somefile.conf', 'some_section');
Within a template, the config variables use special notation: #var_name#. Once a configuration file, or a section of it, is loaded, any placeholder in the template in the form of #var_name# will be replaced with the corresponding value from the configuration file.
The Smarty Debugging Console - php smarty function

Article continues:  next page>>

 Download NuSphere PHP IDE

Download a free trial of the fast PHP EDitor and robust Integrated Development Environment for PHP.

 Buy NuSphere PhpED® now

Best PHP Editor and complete PHP IDE.
NuSphere PhpED 21.0 is available from our online store front.

 Special Team4 Offer

Get 4 copies of PhpED for the price of 3!

Optimum solution for development teams.
PhpED 21.0 Team4
Need more than 4 licenses? Contact Us for more quantity discounts, please use "Ordering/Payment issue" subject on the form.
"To be honest its bloody awesome, I have looked at loads of PHP editors and this is THE only one that actual works straight out of the box!!! Brilliant, well done."
Andrew Breward,
Director of Technology
caboodal.com