Get Smarty


Donate Bitcoin Bitcoin

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Buy cheap glasses from and save up to 80%.

Where to buy prescription glasses? is your best choice!

Where to buy discount wedding dresses and cheap smart dresses free shipping -

Brautkleider auf

Buy New Arrival Cheap Prom Dresses 2015 at JDBRIDAL Prom Dress Store

Find Wedding Dresses Online at Canada from

Cheap bridesmaid dresses - rush delivery only 10 days delivery to Australia at

where cheap prom dresses uk at


Compiler Functions

Compiler functions are called only during compilation of the template. They are useful for injecting PHP code or time-sensitive static content into the template. If there is both a compiler function and a custom function registered under the same name, the compiler function has precedence.

mixed smarty_compiler_name( $params,  
array $params;
object $smarty;

The compiler function is passed two parameters: the params array which contains precompiled strings for the attribute values and the Smarty object. It's supposed to return the code to be injected into the compiled template including the surrounding PHP tags.

Example 18.6. A simple compiler function

 * Smarty plugin
 * -------------------------------------------------------------
 * File:     compiler.tplheader.php
 * Type:     compiler
 * Name:     tplheader
 * Purpose:  Output header containing the source file name and
 *           the time it was compiled.
 * -------------------------------------------------------------
function smarty_compiler_tplheader($params, Smarty $smarty)
    return "<?php\necho '" . $smarty->_current_file . " compiled at " . date('Y-m-d H:M'). "';\n?>";

This function can be called from the template as:

{* this function gets executed at compile time only *}


The resulting PHP code in the compiled template would be something like this:

echo 'index.tpl compiled at 2002-02-20 20:02';


See also registerPlugin(), unregisterPlugin().

No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Email: (not shown)
What is 14 plus 10? (Are you human?)