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 Functions

Smarty supports its own functions, called smarty template functions.

Using Smarty PHP Functions

To call a Smarty function, place the function name within the Smarty tags:
{function_name}
Smarty has both built-in and custom functions. Many of the built-in functions provide logical structures, like conditionals and loops.

Function Attributes

To pass values to the function when calling it, follow the function name with name="value" pairs:
{function_name name1="some value" name2="some other value"}
If the value of an attribute should be a variable, do not quote it:
{function_name name1=$var name2="some other value"}
As with PHP, variables can be put within double quotation marks:
{include file="$filename.tpl"}
Single quotes in that example would not work.

Including Other Files

Smarty supports the ability to include templates within templates. Most commonly this would be used when a site has standard header, footer, navigation, and other elements. The "include" function can include another template within the current template. It's first argument is the name of the file to be included:
{include file='filename.tpl'}
By passing the include function an attribute matching a variable within the included template, you can pass variables:
{include file='filename.tpl' var_name='some value'}    

{* filename.tpl *} 
Something: $var_name
Similar to "include" is "insert", which creates a non-cached section of a template. This is discussed on the Smarty Caching page.

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