\Smarty

Summary

Methods
Properties
Constants
__construct()
assign()
assign_by_ref()
append()
append_by_ref()
clear_assign()
register_function()
unregister_function()
register_object()
unregister_object()
register_block()
unregister_block()
register_compiler_function()
unregister_compiler_function()
register_modifier()
unregister_modifier()
register_resource()
unregister_resource()
register_prefilter()
unregister_prefilter()
register_postfilter()
unregister_postfilter()
register_outputfilter()
unregister_outputfilter()
load_filter()
clear_cache()
clear_all_cache()
is_cached()
clear_all_assign()
clear_compiled_tpl()
template_exists()
get_template_vars()
get_config_vars()
trigger_error()
display()
fetch()
config_load()
get_registered_object()
clear_config()
_get_plugin_filepath()
_is_compiled()
_compile_resource()
_compile_source()
_get_compile_path()
_fetch_resource_info()
_parse_resource_name()
_run_mod_handler()
_dequote()
_read_file()
_get_auto_filename()
_unlink()
_get_auto_id()
_trigger_fatal_error()
_process_compiled_include_callback()
_smarty_include()
_smarty_cache_attrs()
_include()
_eval()
_get_filter_name()
striphtml()
$template_dir
$compile_dir
$config_dir
$plugins_dir
$debugging
$error_reporting
$debug_tpl
$debugging_ctrl
$compile_check
$force_compile
$caching
$cache_dir
$cache_lifetime
$cache_modified_check
$php_handling
$security
$secure_dir
$security_settings
$trusted_dir
$left_delimiter
$right_delimiter
$request_vars_order
$request_use_auto_globals
$compile_id
$use_sub_dirs
$default_modifiers
$default_resource_type
$cache_handler_func
$autoload_filters
$config_overwrite
$config_booleanize
$config_read_hidden
$config_fix_newlines
$default_template_handler_func
$compiler_file
$compiler_class
$config_class
$_tpl_vars
$_smarty_vars
$_sections
$_foreach
$_tag_stack
$_conf_obj
$_config
$_smarty_md5
$_version
$_inclusion_depth
$_compile_id
$_smarty_debug_id
$_smarty_debug_info
$_cache_info
$_file_perms
$_dir_perms
$_reg_objects
$_plugins
$_cache_serials
$_cache_include
$_cache_including
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Properties

$template_dir

$template_dir : string

The name of the directory where templates are located.

Type

string

$compile_dir

$compile_dir : string

The directory where compiled templates are located.

Type

string

$config_dir

$config_dir : string

The directory where config files are located.

Type

string

$plugins_dir

$plugins_dir : array

An array of directories searched for plugins.

Type

array

$debugging

$debugging : boolean

If debugging is enabled, a debug console window will display when the page loads (make sure your browser allows unrequested popup windows)

Type

boolean

$error_reporting

$error_reporting : integer

When set, smarty does uses this value as error_reporting-level.

Type

integer

$debug_tpl

$debug_tpl : string

This is the path to the debug console template. If not set, the default one will be used.

Type

string

$debugging_ctrl

$debugging_ctrl : string

This determines if debugging is enable-able from the browser.

  • NONE => no debugging control allowed
  • URL => enable debugging when SMARTY_DEBUG is found in the URL.

Type

string

$compile_check

$compile_check : boolean

This tells Smarty whether to check for recompiling or not. Recompiling does not need to happen unless a template or config file is changed.

Typically you enable this during development, and disable for production.

Type

boolean

$force_compile

$force_compile : boolean

This forces templates to compile every time. Useful for development or debugging.

Type

boolean

$caching

$caching : integer

This enables template caching.

  • 0 = no caching
  • 1 = use class cache_lifetime value
  • 2 = use cache_lifetime in cache file

Type

integer

$cache_dir

$cache_dir : string

The name of the directory for cache files.

Type

string

$cache_lifetime

$cache_lifetime : integer

This is the number of seconds cached content will persist.

  • 0 = always regenerate cache
  • -1 = never expires

Type

integer

$cache_modified_check

$cache_modified_check : boolean

Only used when $caching is enabled. If true, then If-Modified-Since headers are respected with cached content, and appropriate HTTP headers are sent.

This way repeated hits to a cached page do not send the entire page to the client every time.

Type

boolean

$php_handling

$php_handling : integer

This determines how Smarty handles "<?php .

.. ?>" tags in templates. possible values:

  • SMARTY_PHP_PASSTHRU -> print tags as plain text
  • SMARTY_PHP_QUOTE -> escape tags as entities
  • SMARTY_PHP_REMOVE -> remove php tags
  • SMARTY_PHP_ALLOW -> execute php tags

Type

integer

$security

$security : boolean

This enables template security. When enabled, many things are restricted in the templates that normally would go unchecked. This is useful when untrusted parties are editing templates and you want a reasonable level of security. (no direct execution of PHP in templates for example)

Type

boolean

$secure_dir

$secure_dir : array

This is the list of template directories that are considered secure. This is used only if {@link $security} is enabled. One directory per array element. {@link $template_dir} is in this list implicitly.

Type

array

$security_settings

$security_settings : array

These are the security settings for Smarty. They are used only when {@link $security} is enabled.

Type

array

$trusted_dir

$trusted_dir : array

This is an array of directories where trusted php scripts reside.

\$security is disabled during their inclusion/execution.

Type

array

$left_delimiter

$left_delimiter : string

The left delimiter used for the template tags.

Type

string

$right_delimiter

$right_delimiter : string

The right delimiter used for the template tags.

Type

string

$request_vars_order

$request_vars_order : string

The order in which request variables are registered, similar to variables_order in php.ini E = Environment, G = GET, P = POST, C = Cookies, S = Server

Type

string

$request_use_auto_globals

$request_use_auto_globals : boolean

Indicates wether $HTTP_*_VARS[] (request_use_auto_globals=false) are uses as request-vars or $_*[]-vars. note: if request_use_auto_globals is true, then $request_vars_order has no effect, but the php-ini-value "gpc_order"

Type

boolean

$compile_id

$compile_id : string

Set this if you want different sets of compiled files for the same templates. This is useful for things like different languages.

Instead of creating separate sets of templates per language, you set different compile_ids like 'en' and 'de'.

Type

string

$use_sub_dirs

$use_sub_dirs : boolean

This tells Smarty whether or not to use sub dirs in the cache/ and templates_c/ directories. sub directories better organized, but may not work well with PHP safe mode enabled.

Type

boolean

$default_modifiers

$default_modifiers : array

This is a list of the modifiers to apply to all template variables.

Put each modifier in a separate array element in the order you want them applied. example: array('escape:"htmlall"');

Type

array

$default_resource_type

$default_resource_type : array

This is the resource type to be used when not specified at the beginning of the resource path. examples: $smarty->display('file:index.tpl'); $smarty->display('db:index.tpl'); $smarty->display('index.tpl'); // will use default resource type {include file="file:index.tpl"} {include file="db:index.tpl"} {include file="index.tpl"} {* will use default resource type *}

Type

array

$cache_handler_func

$cache_handler_func : null|string

The function used for cache file handling. If not set, built-in caching is used.

Type

null|string — function name

$autoload_filters

$autoload_filters : array

This indicates which filters are automatically loaded into Smarty.

Type

array — array of filter names

$config_overwrite

$config_overwrite : 

This tells if config file vars of the same name overwrite each other or not.

if disabled, same name variables are accumulated in an array.

Type

$config_booleanize

$config_booleanize : 

This tells whether or not to automatically booleanize config file variables.

If enabled, then the strings "on", "true", and "yes" are treated as boolean true, and "off", "false" and "no" are treated as boolean false.

Type

$config_read_hidden

$config_read_hidden : 

This tells whether hidden sections [.foobar] are readable from the tempalates or not. Normally you would never allow this since that is the point behind hidden sections: the application can access them, but the templates cannot.

Type

$config_fix_newlines

$config_fix_newlines : 

This tells whether or not automatically fix newlines in config files.

It basically converts \r (mac) or \r\n (dos) to \n

Type

$default_template_handler_func

$default_template_handler_func : string

If a template cannot be found, this PHP function will be executed.

Useful for creating templates on-the-fly or other special action.

Type

string — function name

$compiler_file

$compiler_file : string

The file that contains the compiler class. This can a full pathname, or relative to the php_include path.

Type

string

$compiler_class

$compiler_class : string

The class used for compiling templates.

Type

string

$config_class

$config_class : string

The class used to load config vars.

Type

string

$_tpl_vars

$_tpl_vars : array

where assigned template vars are kept

Type

array

$_smarty_vars

$_smarty_vars : null|array

stores run-time $smarty.* vars

Type

null|array

$_sections

$_sections : array

keeps track of sections

Type

array

$_foreach

$_foreach : array

keeps track of foreach blocks

Type

array

$_tag_stack

$_tag_stack : array

keeps track of tag hierarchy

Type

array

$_conf_obj

$_conf_obj : \Config_file

configuration object

Type

\Config_file

$_config

$_config : array

loaded configuration settings

Type

array

$_smarty_md5

$_smarty_md5 : string

md5 checksum of the string 'Smarty'

Type

string

$_version

$_version : string

Smarty version number

Type

string

$_inclusion_depth

$_inclusion_depth : integer

current template inclusion depth

Type

integer

$_compile_id

$_compile_id : string

for different compiled templates

Type

string

$_smarty_debug_id

$_smarty_debug_id : string

text in URL to enable debug mode

Type

string

$_smarty_debug_info

$_smarty_debug_info : array

debugging information for debug console

Type

array

$_cache_info

$_cache_info : array

info that makes up a cache file

Type

array

$_file_perms

$_file_perms : integer

default file permissions

Type

integer

$_dir_perms

$_dir_perms : integer

default dir permissions

Type

integer

$_reg_objects

$_reg_objects : array

registered objects

Type

array

$_plugins

$_plugins : array

table keeping track of plugins

Type

array

$_cache_serials

$_cache_serials : array

cache serials

Type

array

$_cache_include

$_cache_include : string

name of optional cache include file

Type

string

$_cache_including

$_cache_including : string

indicate if the current code is used in a compiled include

Type

string

Methods

__construct()

__construct() 

assign()

assign(array|string  $tpl_var, mixed  $value = null) 

assigns values to template variables

Parameters

array|string $tpl_var

the template variable name(s)

mixed $value

the value to assign

assign_by_ref()

assign_by_ref(string  $tpl_var, mixed  $value) 

assigns values to template variables by reference

Parameters

string $tpl_var

the template variable name

mixed $value

the referenced value to assign

append()

append(array|string  $tpl_var, mixed  $value = null,   $merge = false) 

appends values to template variables

Parameters

array|string $tpl_var

the template variable name(s)

mixed $value

the value to append

$merge

append_by_ref()

append_by_ref(string  $tpl_var, mixed  $value,   $merge = false) 

appends values to template variables by reference

Parameters

string $tpl_var

the template variable name

mixed $value

the referenced value to append

$merge

clear_assign()

clear_assign(string  $tpl_var) 

clear the given assigned template variable.

Parameters

string $tpl_var

the template variable to clear

register_function()

register_function(string  $function, string  $function_impl,   $cacheable = true,   $cache_attrs = null) 

Registers custom function to be used in templates

Parameters

string $function

the name of the template function

string $function_impl

the name of the PHP function to register

$cacheable
$cache_attrs

unregister_function()

unregister_function(string  $function) 

Unregisters custom function

Parameters

string $function

name of template function

register_object()

register_object(string  $object,   $object_impl, null|array  $allowed = array(), boolean  $smarty_args = true,   $block_methods = array()) 

Registers object to be used in templates

Parameters

string $object

name of template object

$object_impl
null|array $allowed

list of allowed methods (empty = all)

boolean $smarty_args

smarty argument format, else traditional

$block_methods

unregister_object()

unregister_object(string  $object) 

Unregisters object

Parameters

string $object

name of template object

register_block()

register_block(string  $block, string  $block_impl,   $cacheable = true,   $cache_attrs = null) 

Registers block function to be used in templates

Parameters

string $block

name of template block

string $block_impl

PHP function to register

$cacheable
$cache_attrs

unregister_block()

unregister_block(string  $block) 

Unregisters block function

Parameters

string $block

name of template function

register_compiler_function()

register_compiler_function(string  $function, string  $function_impl,   $cacheable = true) 

Registers compiler function

Parameters

string $function

name of template function

string $function_impl

name of PHP function to register

$cacheable

unregister_compiler_function()

unregister_compiler_function(string  $function) 

Unregisters compiler function

Parameters

string $function

name of template function

register_modifier()

register_modifier(string  $modifier, string  $modifier_impl) 

Registers modifier to be used in templates

Parameters

string $modifier

name of template modifier

string $modifier_impl

name of PHP function to register

unregister_modifier()

unregister_modifier(string  $modifier) 

Unregisters modifier

Parameters

string $modifier

name of template modifier

register_resource()

register_resource(string  $type, array  $functions) 

Registers a resource to fetch a template

Parameters

string $type

name of resource

array $functions

array of functions to handle resource

unregister_resource()

unregister_resource(string  $type) 

Unregisters a resource

Parameters

string $type

name of resource

register_prefilter()

register_prefilter(callback  $function) 

Registers a prefilter function to apply to a template before compiling

Parameters

callback $function

unregister_prefilter()

unregister_prefilter(callback  $function) 

Unregisters a prefilter function

Parameters

callback $function

register_postfilter()

register_postfilter(callback  $function) 

Registers a postfilter function to apply to a compiled template after compilation

Parameters

callback $function

unregister_postfilter()

unregister_postfilter(callback  $function) 

Unregisters a postfilter function

Parameters

callback $function

register_outputfilter()

register_outputfilter(callback  $function) 

Registers an output filter function to apply to a template output

Parameters

callback $function

unregister_outputfilter()

unregister_outputfilter(callback  $function) 

Unregisters an outputfilter function

Parameters

callback $function

load_filter()

load_filter(string  $type, string  $name) 

load a filter of specified type and name

Parameters

string $type

filter type

string $name

filter name

clear_cache()

clear_cache(string  $tpl_file = null, string  $cache_id = null, string  $compile_id = null, string  $exp_time = null) : boolean

clear cached content for the given template and cache id

Parameters

string $tpl_file

name of template file

string $cache_id

name of cache_id

string $compile_id

name of compile_id

string $exp_time

expiration time

Returns

boolean

clear_all_cache()

clear_all_cache(string  $exp_time = null) : boolean

clear the entire contents of cache (all templates)

Parameters

string $exp_time

expire time

Returns

boolean —

results of {@link smarty_core_rm_auto()}

is_cached()

is_cached(string  $tpl_file, string  $cache_id = null, string  $compile_id = null) : string|false

test to see if valid cache exists for this template

Parameters

string $tpl_file

name of template file

string $cache_id
string $compile_id

Returns

string|false —

results of {@link _read_cache_file()}

clear_all_assign()

clear_all_assign() 

clear all the assigned template variables.

clear_compiled_tpl()

clear_compiled_tpl(string  $tpl_file = null, string  $compile_id = null, string  $exp_time = null) : boolean

clears compiled version of specified template resource, or all compiled template files if one is not specified.

This function is for advanced use only, not normally needed.

Parameters

string $tpl_file
string $compile_id
string $exp_time

Returns

boolean —

results of {@link smarty_core_rm_auto()}

template_exists()

template_exists(string  $tpl_file) : boolean

Checks whether requested template exists.

Parameters

string $tpl_file

Returns

boolean

get_template_vars()

get_template_vars(string  $name = null) : array

Returns an array containing template variables

Parameters

string $name

Returns

array

get_config_vars()

get_config_vars(string  $name = null) : array

Returns an array containing config variables

Parameters

string $name

Returns

array

trigger_error()

trigger_error(string  $error_msg, integer  $error_type = E_USER_WARNING) 

trigger Smarty error

Parameters

string $error_msg
integer $error_type

display()

display(string  $resource_name, string  $cache_id = null, string  $compile_id = null) 

executes & displays the template results

Parameters

string $resource_name
string $cache_id
string $compile_id

fetch()

fetch(string  $resource_name, string  $cache_id = null, string  $compile_id = null, boolean  $display = false) 

executes & returns or displays the template results

Parameters

string $resource_name
string $cache_id
string $compile_id
boolean $display

config_load()

config_load(string  $file, string  $section = null, string  $scope = 'global') 

load configuration values

Parameters

string $file
string $section
string $scope

get_registered_object()

get_registered_object(string  $name) : object

return a reference to a registered object

Parameters

string $name

Returns

object

clear_config()

clear_config(string  $var = null) 

clear configuration values

Parameters

string $var

_get_plugin_filepath()

_get_plugin_filepath(string  $type, string  $name) : string|false

get filepath of requested plugin

Parameters

string $type
string $name

Returns

string|false

_is_compiled()

_is_compiled(string  $resource_name, string  $compile_path) : boolean

test if resource needs compiling

Parameters

string $resource_name
string $compile_path

Returns

boolean

_compile_resource()

_compile_resource(string  $resource_name, string  $compile_path) : boolean

compile the template

Parameters

string $resource_name
string $compile_path

Returns

boolean

_compile_source()

_compile_source(string  $resource_name, string  $source_content, string  $compiled_content,   $cache_include_path = null) : boolean

compile the given source

Parameters

string $resource_name
string $source_content
string $compiled_content
$cache_include_path

Returns

boolean

_get_compile_path()

_get_compile_path(string  $resource_name) : string

Get the compile path for this resource

Parameters

string $resource_name

Returns

string —

results of {@link _get_auto_filename()}

_fetch_resource_info()

_fetch_resource_info(  $params) : boolean

fetch the template info. Gets timestamp, and source if get_source is true

sets $source_content to the source of the template, and $resource_timestamp to its time stamp

Parameters

$params

Returns

boolean

_parse_resource_name()

_parse_resource_name(  $params) : boolean

parse out the type and name from the resource

Parameters

$params

Returns

boolean

_run_mod_handler()

_run_mod_handler() : string

Handle modifiers

Returns

string —

result of modifiers

_dequote()

_dequote(string  $string) : string

Remove starting and ending quotes from the string

Parameters

string $string

Returns

string

_read_file()

_read_file(string  $filename) : string

read in a file

Parameters

string $filename

Returns

string

_get_auto_filename()

_get_auto_filename(string  $auto_base, string  $auto_source = null, string  $auto_id = null) : string

get a concrete filename for automagically created content

Parameters

string $auto_base
string $auto_source
string $auto_id

Returns

string

_unlink()

_unlink(string  $resource, integer  $exp_time = null) 

unlink a file, possibly using expiration time

Parameters

string $resource
integer $exp_time

_get_auto_id()

_get_auto_id(string  $cache_id = null, string  $compile_id = null) : string|null

returns an auto_id for auto-file-functions

Parameters

string $cache_id
string $compile_id

Returns

string|null

_trigger_fatal_error()

_trigger_fatal_error(string  $error_msg, string  $tpl_file = null, integer  $tpl_line = null, string  $file = null, integer  $line = null, integer  $error_type = E_USER_ERROR) 

trigger Smarty plugin error

Parameters

string $error_msg
string $tpl_file
integer $tpl_line
string $file
integer $line
integer $error_type

_process_compiled_include_callback()

_process_compiled_include_callback(  $match) : string

callback function for preg_replace, to call a non-cacheable block

Parameters

$match

Returns

string

_smarty_include()

_smarty_include(  $params) 

Parameters

$params

_smarty_cache_attrs()

_smarty_cache_attrs(  $cache_serial,   $count) : array

get or set an array of cached attributes for function that is not cacheable

Parameters

$cache_serial
$count

Returns

array

_include()

_include(  $filename,   $once = false,   $params = null) : mixed

wrapper for include() retaining $this

Parameters

$filename
$once
$params

Returns

mixed

_eval()

_eval(  $code,   $params = null) : mixed

wrapper for eval() retaining $this

Parameters

$code
$params

Returns

mixed

_get_filter_name()

_get_filter_name(callback  $function) : string

Extracts the filter name from the given callback

Parameters

callback $function

Returns

string

striphtml()

striphtml(  $html) 

Parameters

$html