\SmartyBC

Smarty Backward Compatibility Wrapper Class

Summary

Methods
Properties
Constants
__construct()
__destruct()
templateExists()
getGlobal()
clearAllCache()
clearCache()
enableSecurity()
disableSecurity()
setTemplateDir()
addTemplateDir()
getTemplateDir()
setConfigDir()
addConfigDir()
getConfigDir()
setPluginsDir()
addPluginsDir()
getPluginsDir()
setCompileDir()
getCompileDir()
setCacheDir()
getCacheDir()
setDefaultModifiers()
addDefaultModifiers()
getDefaultModifiers()
setAutoloadFilters()
addAutoloadFilters()
getAutoloadFilters()
createTemplate()
loadPlugin()
compileAllTemplates()
compileAllConfig()
clearCompiledTemplate()
getTags()
testInstall()
mutingErrorHandler()
muteExpectedErrors()
unmuteExpectedErrors()
fetch()
display()
isCached()
createData()
registerPlugin()
unregisterPlugin()
registerResource()
unregisterResource()
registerCacheResource()
unregisterCacheResource()
registerObject()
getRegisteredObject()
unregisterObject()
registerClass()
registerDefaultPluginHandler()
registerDefaultTemplateHandler()
registerDefaultConfigHandler()
registerFilter()
unregisterFilter()
loadFilter()
unloadFilter()
assign()
assignGlobal()
assignByRef()
append()
appendByRef()
getTemplateVars()
clearAssign()
clearAllAssign()
configLoad()
getVariable()
getConfigVariable()
getStreamVariable()
getConfigVars()
clearConfig()
assign_by_ref()
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()
config_load()
get_registered_object()
clear_config()
trigger_error()
$auto_literal
$error_unassigned
$use_include_path
$default_template_handler_func
$default_config_handler_func
$default_plugin_handler_func
$force_compile
$compile_check
$use_sub_dirs
$allow_ambiguous_resources
$caching
$merge_compiled_includes
$inheritance_merge_compiled_includes
$cache_lifetime
$force_cache
$cache_id
$compile_id
$safe_lookups
$left_delimiter
$right_delimiter
$security_class
$security_policy
$direct_access_security
$error_reporting
$config_overwrite
$config_booleanize
$config_read_hidden
$compile_locking
$cache_locking
$locking_timeout
$default_resource_type
$caching_type
$default_config_type
$plugin_search_order
$default_modifiers
$escape_html
$_version
SMARTY_VERSION
SCOPE_LOCAL
SCOPE_PARENT
SCOPE_ROOT
SCOPE_GLOBAL
CACHING_OFF
CACHING_LIFETIME_CURRENT
CACHING_LIFETIME_SAVED
CLEAR_EXPIRED
COMPILECHECK_OFF
COMPILECHECK_ON
COMPILECHECK_CACHEMISS
FILTER_POST
FILTER_PRE
FILTER_OUTPUT
FILTER_VARIABLE
PLUGIN_FUNCTION
PLUGIN_BLOCK
PLUGIN_COMPILER
PLUGIN_MODIFIER
PLUGIN_MODIFIERCOMPILER
LOOKUP_UNSAFE
LOOKUP_SAFE
LOOKUP_SAFE_WARN
No protected methods found
No protected properties found
N/A
replaceCamelcase()
$template_dir
$compile_dir
$plugins_dir
$cache_dir
$config_dir
N/A

Constants

SMARTY_VERSION

SMARTY_VERSION

The current version string for the current version of Brainy.

SCOPE_LOCAL

SCOPE_LOCAL

Represents local scope.

SCOPE_PARENT

SCOPE_PARENT

Represents the parent template's scope.

SCOPE_ROOT

SCOPE_ROOT

Represents the root template's scope.

SCOPE_GLOBAL

SCOPE_GLOBAL

Represents the global scope.

CACHING_OFF

CACHING_OFF

Represents disabled caching.

CACHING_LIFETIME_CURRENT

CACHING_LIFETIME_CURRENT

When used, $cache_lifetime will be used to determine if the cache has expired.

CACHING_LIFETIME_SAVED

CACHING_LIFETIME_SAVED

When used, $cache_lifetime will be used to determine if the cache has expired at the time the cache is generated.

CLEAR_EXPIRED

CLEAR_EXPIRED

When passed to various cache-clearing methods, expired cache items will be removed.

COMPILECHECK_OFF

COMPILECHECK_OFF

Disables checking templates of compiled files to detect changes.

COMPILECHECK_ON

COMPILECHECK_ON

Enables checking templates of compiled files to detect changes.

COMPILECHECK_CACHEMISS

COMPILECHECK_CACHEMISS

Enables checking templates of compiled files to detect changes when a cache miss occurs.

FILTER_POST

FILTER_POST

Represents post-filtering

FILTER_PRE

FILTER_PRE

Represents pre-filtering

FILTER_OUTPUT

FILTER_OUTPUT

Represents output-filtering

FILTER_VARIABLE

FILTER_VARIABLE

Represents variable-filtering

PLUGIN_FUNCTION

PLUGIN_FUNCTION

Represents a function plugin

PLUGIN_BLOCK

PLUGIN_BLOCK

Represents a block plugin

PLUGIN_COMPILER

PLUGIN_COMPILER

Represents a compiler plugin

PLUGIN_MODIFIER

PLUGIN_MODIFIER

Represents a modifier plugin

PLUGIN_MODIFIERCOMPILER

PLUGIN_MODIFIERCOMPILER

Represents a modifiercompiler plugin

LOOKUP_UNSAFE

LOOKUP_UNSAFE

When used, lookups will be unsafe (default Smarty 3 behavior)

LOOKUP_SAFE

LOOKUP_SAFE

When used, lookups will be safe (default Smarty 2 behavior)

LOOKUP_SAFE_WARN

LOOKUP_SAFE_WARN

When used, lookups will be safe and a warning will be raised using trigger_error.

Properties

$auto_literal

$auto_literal : boolean

When `true`, delimiter strings will be ignored if they are surrounded by whitespace.

Type

boolean

$error_unassigned

$error_unassigned : boolean

When `true`, an error will be displayed when accessing undefined variables.

Type

boolean

$use_include_path

$use_include_path : boolean

When `true`, the include_path will be respected for finding file resources.

Type

boolean

$default_template_handler_func

$default_template_handler_func : callable

Expects a function to use to fetch templates when it cannot be fetched through the default means. The function should use the following prototype:

  • string $resource_type
  • string $resource_name
  • string &$config_content
  • int &$modified_timestamp
  • Smarty $smarty

It is expected to return a string (a path to a file) or false if no template could be loaded.

Type

callable

$default_config_handler_func

$default_config_handler_func : callable

Expects a function to use to fetch config when it cannot be fetched through the default means. The function should use the following prototype:

  • string $resource_type
  • string $resource_name
  • string &$template_content
  • int &$modified_timestamp
  • Smarty $smarty

It is expected to return a string (a path to a file) or false if no config could be loaded.

Type

callable

$default_plugin_handler_func

$default_plugin_handler_func : callable

Expects a function to use to fetch plugins when it cannot be fetched through the default means. The function should use the following prototype:

  • string $resource_type
  • string $resource_name
  • string &$config_content
  • int &$modified_timestamp
  • Smarty $smarty

It is expected to return a string (a path to a file) or false if no plugin could be loaded.

Type

callable

$force_compile

$force_compile : boolean

When true, Brainy will never use the compiled versions of templates, though compiled files will continue to be generated. This overrides `Smarty::$compile_check`. Do not use this in production.

Type

boolean

$compile_check

$compile_check : boolean|integer

When true or Smarty::COMPILECHECK_ON, templates and config are checked for changes. If changes exist, the template will be recompiled regardless of whether it has been compiled or cached. Disabling this in production may yield performance improvements if templates and config do not change. If set to Smarty::COMPILECHECK_CACHEMISS, compiled templates are revalidated once a cache file is generated, preventing multiple compile_checks when a cached template expires.

Type

boolean|integer

$use_sub_dirs

$use_sub_dirs : boolean

When true, subdirectories will be created within the cache and compile directories. This is useful for applications with very large numbers of templates, as it minimizes the number of files in each of the directories. This does not work when PHP's safe_mode is set to on.

Type

boolean

$allow_ambiguous_resources

$allow_ambiguous_resources : boolean

When true, ambiguous resources are allowed.

Type

boolean

$caching

$caching : boolean|integer

Controls the caching strategy.

  • Smarty::CACHING_LIFETIME_CURRENT and Smarty::CACHING_LIFETIME_SAVED enable caching.
  • Smarty::CACHING_LIFETIME_CURRENT uses $cache_lifetime to determine if the cache has expired.
  • Smarty::CACHING_LIFETIME_SAVED works similarly, except $cache_lifetime is checked at the time the cache is generated.
  • If $compile_check is true, cached content will be regenerated when the templates or configs change.
  • If $force_compile is true, caching will be disabled.

Type

boolean|integer

$merge_compiled_includes

$merge_compiled_includes : boolean

When true, included templates will be compiled into the templates that they are included in. The {include} function has an attribute that allows this to be performed on a case-by-case basis.

Type

boolean

$inheritance_merge_compiled_includes

$inheritance_merge_compiled_includes : boolean

When true, templates will be compiled into the templates that they inherit from.

Type

boolean

$cache_lifetime

$cache_lifetime : integer

The amount of time that a cached template will live for.

Smarty::$caching must be turned on for this to have an effect.

-1 will prevent the cache from expiring. 0 will disable the cache.

Type

integer

$force_cache

$force_cache : boolean

When true, Brainy will never use the cached versions of templates, though cache files will continue to be generated if Smarty::$caching specifies it. Do not use this in production.

Type

boolean

$cache_id

$cache_id : string

Set this if you want different sets of cache files for the same templates.

Type

string

$compile_id

$compile_id : string

Set this if you want different sets of compiled files for the same templates.

Type

string

$safe_lookups

$safe_lookups : integer

Indicates whether to perform only safe variable and member lookups.

If set to LOOKUP_SAFE, lookups referring to missing variables or members will return a falsey value. LOOKUP_SAFE_WARN will log a warning when the member does not exist.

Type

integer

$left_delimiter

$left_delimiter : string

The left delimiter string

Type

string

$right_delimiter

$right_delimiter : string

The right delimiter string

Type

string

$security_class

$security_class : string

The name of the class to use for security.

Type

string

$security_policy

$security_policy : \Smarty_Security

The Smarty_Security instance to use as a security policy.

Type

\Smarty_Security

$direct_access_security

$direct_access_security : boolean

When true, browsers will be blocked from accessing compiled or cached templates. Changing this to false is not recommended.

{@internal Currently used by Smarty_Internal_Template only. }}

Type

boolean

$error_reporting

$error_reporting : integer|null

When set, this will be used as the default error reporting level.

Type

integer|null

$config_overwrite

$config_overwrite : boolean

When true, repeated values in config files will overwrite previous config values with the same name.

Type

boolean

$config_booleanize

$config_booleanize : boolean

When true, config values of on/true/yes and off/false/no get converted to boolean values automatically rather than returning their string value.

Type

boolean

$config_read_hidden

$config_read_hidden : boolean

When true, hidden sections in config (sections whose names begin with a dot) will not be hidden.

Type

boolean

$compile_locking

$compile_locking : boolean

When true, concurrent template compilation is disabled.

Type

boolean

$cache_locking

$cache_locking : boolean

When true, cached templates will not be generated concurrently by multiple requests.

Type

boolean

$locking_timeout

$locking_timeout : float

The maximum amount of time (in seconds) that a cached template will lock for, when $cache_locking is set.

Type

float

$default_resource_type

$default_resource_type : string

resource type used if none given

Must be an valid key of $registered_resources.

Type

string

$caching_type

$caching_type : string

The type of resource to use to load templates.

Must be an element of Smarty::$cache_resource_types.

Type

string

$default_config_type

$default_config_type : string

The type of resource to use to load config.

Must be an element of Smarty::$cache_resource_types.

Type

string

$plugin_search_order

$plugin_search_order : array<mixed,string>

The order in which to search for plugins

Type

array<mixed,string>

$default_modifiers

$default_modifiers : array

default modifier

Type

array

$escape_html

$escape_html : boolean

When true, all variables will be implicitly wrapped in

htmlspecialchars({$variable}, ENT_QUOTES, SMARTY_RESOURCE_CHAR_SET)

Variables may use the {$variable nofilter} syntax to prevent this behavior.

Type

boolean

$_version

$_version : string

Smarty 2 BC

Type

string

$template_dir

$template_dir : array|null

Directory that cached templates are stored in. See the following methods instead:

  • Smarty::setTemplateDir()
  • Smarty::getTemplateDir()
  • Smarty::addTemplateDir()

Type

array|null

$compile_dir

$compile_dir : string|null

Directory that compiled templates are stored in. See the following methods instead:

  • Smarty::setCompileDir()
  • Smarty::getCompileDir()

Type

string|null

$plugins_dir

$plugins_dir : string|array|null

Directory that plugins are stored in. See the following methods instead:

  • Smarty::setPluginsDir()
  • Smarty::getPluginsDir()
  • Smarty::addPluginsDir()

Type

string|array|null

$cache_dir

$cache_dir : string|null

Directory that cached templates are stored in. See the following methods instead:

  • Smarty::setCacheDir()
  • Smarty::getCacheDir()

Type

string|null

$config_dir

$config_dir : string|array|null

Directory that config files are stored in. See the following methods instead:

  • Smarty::setConfigDir()
  • Smarty::getConfigDir()
  • Smarty::addConfigDir()

Type

string|array|null

Methods

__construct()

__construct(array  $options = array()) 

Initialize new SmartyBC object

Parameters

array $options

options to set during initialization, e.g. array( 'forceCompile' => false )

__destruct()

__destruct() 

Class destructor

templateExists()

templateExists(string  $resource_name) : boolean

Returns whether a template with the given name exists

Parameters

string $resource_name

template name

Returns

boolean —

Whether the template exists

getGlobal()

getGlobal(string  $varname = null) : mixed

Returns a single or all global variables

Parameters

string $varname

variable name or null

Returns

mixed —

Variable value or array of variable values

clearAllCache()

clearAllCache(integer|null  $exp_time = null, string|null  $type = null) : integer

Clear the entire template cache folder.

If $expire_time is set, only files older than $expire_time seconds will be deleted. Smarty::CLEAR_EXPIRED can also be passed to delete all expired templates.

Parameters

integer|null $exp_time

expiration time

string|null $type

resource type

Returns

integer —

Number of cache files deleted

clearCache()

clearCache(string  $template_name, string|null  $cache_id = null, string|null  $compile_id = null, integer|null  $exp_time = null, string|null  $type = null) : integer

Empty cache for a specific template.

If $cache_id or $compile_id are specified, they will limit the operation to only cached files with those IDs, respectively. If $expire_time is set, it will be used as the minimum age for files to be deleted. Smarty::CLEAR_EXPIRED can also be passed to delete all expired templates.

Parameters

string $template_name

template name

string|null $cache_id

cache id

string|null $compile_id

compile id

integer|null $exp_time

expiration time

string|null $type

resource type

Returns

integer —

Number of cache files deleted

enableSecurity()

enableSecurity(string|\Smarty_Security  $security_class = null) : \Smarty

Loads security class and enables security

Parameters

string|\Smarty_Security $security_class

if a string is used, it must be class-name

Throws

\SmartyException

when an invalid class name is provided

Returns

\Smarty

The current Smarty instance for chaining

disableSecurity()

disableSecurity() : \Smarty

Disable the currently loaded security policy.

Returns

\Smarty

The current Smarty instance for chaining

setTemplateDir()

setTemplateDir(string|array<mixed,string>  $template_dir) : \Smarty

Set template directory

Parameters

string|array<mixed,string> $template_dir

directory(s) of template sources

Returns

\Smarty

The current Smarty instance for chaining

addTemplateDir()

addTemplateDir(string|array  $template_dir, string|null  $key = null) : \Smarty

Add a directory to the list of directories where templates are stored

Parameters

string|array $template_dir

directory(s) of template sources

string|null $key

of the array element to assign the template dir to

Throws

\SmartyException

when the given template directory is not valid

Returns

\Smarty

The current Smarty instance for chaining

getTemplateDir()

getTemplateDir(integer|null  $index = null) : array|string

Get template directories

Parameters

integer|null $index

of directory to get, null to get all

Returns

array|string —

list of template directories, or directory of $index

setConfigDir()

setConfigDir(string|array<mixed,string>  $config_dir) : \Smarty

Set config directory

Parameters

string|array<mixed,string> $config_dir

directory(s) of configuration sources

Returns

\Smarty

The current Smarty instance for chaining

addConfigDir()

addConfigDir(string|array  $config_dir, string|null  $key = null) : \Smarty

Add a directory to the list of directories where config files are stored.

Parameters

string|array $config_dir

directory(s) of config sources

string|null $key

of the array element to assign the config dir to

Returns

\Smarty

The current Smarty instance for chaining

getConfigDir()

getConfigDir(integer|null  $index = null) : array|string

Get config directory

Parameters

integer|null $index

of directory to get, null to get all

Returns

array|string —

configuration directory

setPluginsDir()

setPluginsDir(string|array  $plugins_dir) : \Smarty

Set plugins directory

Parameters

string|array $plugins_dir

directory(s) of plugins

Returns

\Smarty

current Smarty instance for chaining

addPluginsDir()

addPluginsDir(string|array  $plugins_dir) : \Smarty

Add a directory to the list of directories where plugins are stored

Parameters

string|array $plugins_dir

plugins folder

Returns

\Smarty

current Smarty instance for chaining

getPluginsDir()

getPluginsDir() : array<mixed,string>

Get plugin directories

Returns

array<mixed,string> —

List of plugin directories

setCompileDir()

setCompileDir(string  $compile_dir) : \Smarty

Set compile directory

Parameters

string $compile_dir

directory to store compiled templates in

Returns

\Smarty

current Smarty instance for chaining

getCompileDir()

getCompileDir() : string

Get compiled template directory

Returns

string —

Path to compiled templates

setCacheDir()

setCacheDir(string  $cache_dir) : \Smarty

Set cache directory

Parameters

string $cache_dir

directory to store cached templates in

Returns

\Smarty

current Smarty instance for chaining

getCacheDir()

getCacheDir() : string

Get cached template directory

Returns

string —

Path of cache directory

setDefaultModifiers()

setDefaultModifiers(array|string  $modifiers) : \Smarty

Set default modifiers

Parameters

array|string $modifiers

modifier or list of modifiers to set

Returns

\Smarty

current Smarty instance for chaining

addDefaultModifiers()

addDefaultModifiers(array|string  $modifiers) : \Smarty

Add default modifiers

Parameters

array|string $modifiers

modifier or list of modifiers to add

Returns

\Smarty

current Smarty instance for chaining

getDefaultModifiers()

getDefaultModifiers() : array

Get default modifiers

Returns

array —

list of default modifiers

setAutoloadFilters()

setAutoloadFilters(array  $filters, string|null  $type = null) : \Smarty

Set autoload filters

Parameters

array $filters

filters to load automatically

string|null $type

"pre", "output", … specify the filter type to set. Defaults to none treating $filters' keys as the appropriate types

Returns

\Smarty

current Smarty instance for chaining

addAutoloadFilters()

addAutoloadFilters(array  $filters, string  $type = null) : \Smarty

Add autoload filters

Parameters

array $filters

filters to load automatically

string $type

"pre", "output", … specify the filter type to set. Defaults to none treating $filters' keys as the appropriate types

Returns

\Smarty

current Smarty instance for chaining

getAutoloadFilters()

getAutoloadFilters(string  $type = null) : array

Get autoload filters

Parameters

string $type

type of filter to get autoloads for. Defaults to all autoload filters

Returns

array —

array( 'type1' => array( 'filter1', 'filter2', … ) ) or array( 'filter1', 'filter2', …) if $type was specified

createTemplate()

createTemplate(string  $template, mixed  $cache_id = null, mixed  $compile_id = null, object|null  $parent = null, boolean|null  $do_clone = true) : object

Creates a template object.

This creates a template object which later can be rendered by the Smarty::display() or Smarty::fetch() method.

Parameters

string $template

the resource handle of the template file

mixed $cache_id

cache id to be used with this template

mixed $compile_id

compile id to be used with this template

object|null $parent

Parent scope to assign to the template

boolean|null $do_clone

When true, the Smarty object will be cloned

Returns

object —

template object

loadPlugin()

loadPlugin(string  $plugin_name, boolean  $check = false) : string

Takes unknown classes and loads plugin files for them class name format: Smarty_PluginType_PluginName plugin filename format: plugintype.pluginname.php

Parameters

string $plugin_name

class plugin name to load

boolean $check

check if already loaded

Returns

string —

|boolean filepath of loaded file or false

compileAllTemplates()

compileAllTemplates(string  $extension = '.tpl', boolean  $force_compile = false, integer  $time_limit, integer  $max_errors = null) : integer

Compile all template files

Parameters

string $extension

Optional file extension

boolean $force_compile

Optional boolean that compiles all files instead of modified files

integer $time_limit

Optional integer to specify a runtime limit in seconds for the compilation process

integer $max_errors

Optional integer to set an error limit. If more errors occur, the function will abort

Returns

integer —

number of template files recompiled

compileAllConfig()

compileAllConfig(string  $extension = '.conf', boolean  $force_compile = false, integer  $time_limit, integer  $max_errors = null) : integer

Compile all config files

Parameters

string $extension

Optional file extension

boolean $force_compile

Optional boolean that compiles all files instead of modified files

integer $time_limit

Optional integer to specify a runtime limit in seconds for the compilation process

integer $max_errors

Optional integer to set an error limit. If more errors occur, the function will abort

Returns

integer —

number of config files recompiled

clearCompiledTemplate()

clearCompiledTemplate(string|null  $resource_name = null, string|null  $compile_id = null, integer|null  $exp_time = null) : integer

Delete a compiled template file.

This clears the compiled version of the specified template resource, or all compiled template files if one is not specified. If you pass a $compile_id only the compiled template for this specific $compile_id is cleared. If you pass an $exp_time, then only compiled templates older than $exp_time seconds are cleared, by default all compiled templates are cleared regardless of their age. This function is for advanced use only, not normally needed.

Parameters

string|null $resource_name

template name

string|null $compile_id

compile id

integer|null $exp_time

expiration time

Returns

integer —

number of template files deleted

getTags()

getTags(object  $template) : array

Return array of tag/attributes of all tags used by an template

Parameters

object $template

The template object

Returns

array —

of tag/attributes

testInstall()

testInstall(array  $errors = null) : boolean

Run installation test

This function verifies that all required working folders of the current installation can be accessed appropriately.

Parameters

array $errors

Array to write errors into, rather than outputting them

Returns

boolean —

true if setup is fine, false if something is wrong

mutingErrorHandler()

mutingErrorHandler(integer  $errno,   $errstr,   $errfile,   $errline,   $errcontext) : boolean

Error Handler to mute expected messages

Parameters

integer $errno

Error level

$errstr
$errfile
$errline
$errcontext

Returns

boolean

muteExpectedErrors()

muteExpectedErrors() : void

Enable error handler to mute expected messages

error muting is done because some people implemented custom error_handlers using http://php.net/set_error_handler and for some reason did not understand the following paragraph:

It is important to remember that the standard PHP error handler is completely bypassed for the
error types specified by error_types unless the callback function returns FALSE.
error_reporting() settings will have no effect and your error handler will be called regardless -
however you are still able to read the current value of error_reporting and act appropriately.
Of particular note is that this value will be 0 if the statement that caused the error was
prepended by the @ error-control operator.

A call to @filemtime() is used instead of file_exists() and filemtime() in some places. Reasons include:

  • @filemtime() is almost twice as fast as using an additional file_exists()
  • between file_exists() and filemtime() a possible race condition is opened, which does not exist using the simple \@filemtime() approach.

unmuteExpectedErrors()

unmuteExpectedErrors() : void

Disable error handler muting expected messages

fetch()

fetch(string  $template = null, mixed  $cache_id = null, mixed  $compile_id = null, object  $parent = null, boolean  $display = false, boolean  $merge_tpl_vars = true, boolean  $no_output_filter = false) : string

Renders and returns a template.

This returns the template output instead of displaying it.

Parameters

string $template

the resource handle of the template file or template object

mixed $cache_id

cache id to be used with this template

mixed $compile_id

compile id to be used with this template

object $parent

next higher level of Smarty variables

boolean $display

true: display, false: fetch

boolean $merge_tpl_vars

if true parent template variables merged in to local scope

boolean $no_output_filter

if true do not run output filter

Returns

string —

rendered template output

display()

display(string  $template = null, mixed  $cache_id = null, mixed  $compile_id = null, object  $parent = null) : void

Renders the template.

This displays the contents of a template. To return the contents of a template into a variable, use the fetch() method instead.

As an optional second and third parameter, you can pass a cache ID and compile ID.

A fourth parameter can be passed which passes the parent scope that the template should use.

Parameters

string $template

the resource handle of the template file or template object

mixed $cache_id

cache id to be used with this template

mixed $compile_id

compile id to be used with this template

object $parent

next higher level of Smarty variables

isCached()

isCached(string|object  $template = null, mixed  $cache_id = null, mixed  $compile_id = null) : boolean

Returns whether the template is cached.

Note that calling this method will load the template into memory. Subsequent calls to fetch() or display() will not reload the template file. Calling clearCache() may also have no effect if this method has returned true.

Parameters

string|object $template

the resource handle of the template file or template object

mixed $cache_id

cache id to be used with this template

mixed $compile_id

compile id to be used with this template

Returns

boolean —

The template's cache status

createData()

createData(object|null  $parent = null) : \Smarty_Data

Returns a new data object.

Data objects are used to create scopes for assigned variables. They can be used to have control which variables are seen by which templates.

Parameters

object|null $parent

Optional link to a parent scope

Returns

\Smarty_Data

data object

registerPlugin()

registerPlugin(string  $type, string  $tag, callable  $callback, boolean  $cacheable = true, array|null  $cache_attr = null) : \Smarty_Internal_TemplateBase

Registers plugin to be used in templates

Parameters

string $type

plugin type

string $tag

name of template tag

callable $callback

PHP callback to register

boolean $cacheable

if true (default) this fuction is cachable

array|null $cache_attr

caching attributes if any

Throws

\SmartyException

when the plugin tag is invalid

Returns

\Smarty_Internal_TemplateBase

Self-reference to facilitate chaining

unregisterPlugin()

unregisterPlugin(string  $type, string  $tag) : \Smarty_Internal_TemplateBase

Unregister Plugin

Parameters

string $type

of plugin

string $tag

name of plugin

Returns

\Smarty_Internal_TemplateBase

Self-reference to facilitate chaining

registerResource()

registerResource(string  $type, \Smarty_Resource|array<mixed,\Smarty_Resource>  $callback) : \Smarty_Internal_TemplateBase

Registers a resource to fetch a template

Parameters

string $type

name of resource type

\Smarty_Resource|array<mixed,\Smarty_Resource> $callback

Instance of Smarty_Resource, or array of callbacks to handle resource (deprecated)

Returns

\Smarty_Internal_TemplateBase

Self-reference to facilitate chaining

unregisterResource()

unregisterResource(string  $type) : \Smarty_Internal_TemplateBase

Unregisters a resource

Parameters

string $type

name of resource type

Returns

\Smarty_Internal_TemplateBase

Self-reference to facilitate chaining

registerCacheResource()

registerCacheResource(string  $type, \Smarty_CacheResource  $callback) : \Smarty_Internal_TemplateBase

Registers a cache resource to cache a template's output

Parameters

string $type

Name of cache resource type

\Smarty_CacheResource $callback

instance of Smarty_CacheResource to handle output caching

Returns

\Smarty_Internal_TemplateBase

Self-reference to facilitate chaining

unregisterCacheResource()

unregisterCacheResource(string  $type) : \Smarty_Internal_TemplateBase

Unregisters a cache resource

Parameters

string $type

name of cache resource type

Returns

\Smarty_Internal_TemplateBase

Self-reference to facilitate chaining

registerObject()

registerObject(  $object_name, object  $object_impl, array  $allowed = array(), boolean  $smarty_args = true, array  $block_methods = array()) : \Smarty_Internal_TemplateBase

Registers object to be used in templates

Parameters

$object_name
object $object_impl

the referenced PHP object to register

array $allowed

list of allowed methods (empty = all)

boolean $smarty_args

smarty argument format, else traditional

array $block_methods

list of block-methods

Throws

\SmartyException

if any of the methods in $allowed or $block_methods are invalid

Returns

\Smarty_Internal_TemplateBase

Self-reference to facilitate chaining

getRegisteredObject()

getRegisteredObject(string  $name) : mixed

Returns a reference to a registered object.

Parameters

string $name

object name

Throws

\SmartyException

if no such object is found

Returns

mixed

unregisterObject()

unregisterObject(string  $name) : \Smarty_Internal_TemplateBase

unregister an object

Parameters

string $name

object name

Returns

\Smarty_Internal_TemplateBase

Self-reference to facilitate chaining

registerClass()

registerClass(  $class_name, string  $class_impl) : \Smarty_Internal_TemplateBase

Registers static classes to be used in templates

Parameters

$class_name
string $class_impl

the referenced PHP class to register

Throws

\SmartyException

if $class_impl does not refer to an existing class

Returns

\Smarty_Internal_TemplateBase

Self-reference to facilitate chaining

registerDefaultPluginHandler()

registerDefaultPluginHandler(callable  $callback) : \Smarty_Internal_TemplateBase

Registers a default plugin handler

A default plugin handler gets called on undefined tags.

Parameters

callable $callback

class/method name

Throws

\SmartyException

if $callback is not callable

Returns

\Smarty_Internal_TemplateBase

Self-reference to facilitate chaining

registerDefaultTemplateHandler()

registerDefaultTemplateHandler(callable  $callback) : \Smarty_Internal_TemplateBase

Registers a default template handler

Parameters

callable $callback

class/method name

Throws

\SmartyException

if $callback is not callable

Returns

\Smarty_Internal_TemplateBase

Self-reference to facilitate chaining

registerDefaultConfigHandler()

registerDefaultConfigHandler(callable  $callback) : \Smarty_Internal_TemplateBase

Registers a default template handler

Parameters

callable $callback

class/method name

Throws

\SmartyException

if $callback is not callable

Returns

\Smarty_Internal_TemplateBase

Self-reference to facilitate chaining

registerFilter()

registerFilter(string  $type, callback  $callback) : \Smarty_Internal_TemplateBase

Registers a filter function

Parameters

string $type

filter type

callback $callback

Returns

\Smarty_Internal_TemplateBase

Self-reference to facilitate chaining

unregisterFilter()

unregisterFilter(string  $type, callback  $callback) : \Smarty_Internal_TemplateBase

Unregisters a filter function

Parameters

string $type

filter type

callback $callback

Returns

\Smarty_Internal_TemplateBase

Self-reference to facilitate chaining

loadFilter()

loadFilter(string  $type, string  $name) 

Load a filter of specified type and name

Parameters

string $type

filter type

string $name

filter name

Throws

\SmartyException

if filter could not be loaded

unloadFilter()

unloadFilter(string  $type, string  $name) : \Smarty_Internal_TemplateBase

unload a filter of specified type and name

Parameters

string $type

filter type

string $name

filter name

Returns

\Smarty_Internal_TemplateBase

Self-reference to facilitate chaining

assign()

assign(array|string  $var, mixed  $value = null) : \Smarty_Internal_Data

Assigns $var to the variable in $varname. If an associative array is passed as the only parameter, it is a mapping of variables to assign to the values to assign to them.

Parameters

array|string $var

the template variable name(s)

mixed $value

the value to assign

Returns

\Smarty_Internal_Data

current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining

assignGlobal()

assignGlobal(string  $varname, mixed  $value = null) : \Smarty_Internal_Data

Assigns a global Smarty variable to the global scope.

Parameters

string $varname

the global variable name

mixed $value

the value to assign

Returns

\Smarty_Internal_Data

current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining

assignByRef()

assignByRef(string  $tpl_var,   $value) : \Smarty_Internal_Data

Assigns values to template variables by reference

Parameters

string $tpl_var

the template variable name

$value

Returns

\Smarty_Internal_Data

current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining

append()

append(array|string  $tpl_var, mixed  $value = null, boolean  $merge = false) : \Smarty_Internal_Data

Append an element to an assigned array

If you append to a string value, it is converted to an array value and then appended to. You can explicitly pass name/value pairs, or associative arrays containing the name/value pairs. If you pass the optional third parameter of true, the value will be merged with the current array instead of appended.

The $merge parameter does not use the PHP array_merge function. Merging two numerically indexed arrays may cause values to overwrite each other or result in non-sequential keys.

Parameters

array|string $tpl_var

the template variable name(s)

mixed $value

the value to append

boolean $merge

flag if array elements shall be merged

Returns

\Smarty_Internal_Data

current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining

appendByRef()

appendByRef(string  $tpl_var,   $value, boolean  $merge = false) : \Smarty_Internal_Data

Appends values to template variables by reference

Parameters

string $tpl_var

the template variable name

$value
boolean $merge

flag if array elements shall be merged

Returns

\Smarty_Internal_Data

current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining

getTemplateVars()

getTemplateVars(string  $varname = null, \Smarty_Internal_Data  $_ptr = null, boolean  $search_parents = true) : string|array

Returns a single or all assigned template variables

Parameters

string $varname

Name of variable to process, or null to return all

\Smarty_Internal_Data $_ptr

Optional reference to data object

boolean $search_parents

Whether to include results from parent scopes

Returns

string|array —

variable value or or array of variables

clearAssign()

clearAssign(string|array<mixed,string>  $tpl_var) : \Smarty_Internal_Data

Clear the given assigned template variable.

Parameters

string|array<mixed,string> $tpl_var

The template variable(s) to clear

Returns

\Smarty_Internal_Data

current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining

clearAllAssign()

clearAllAssign() : \Smarty_Internal_Data

Clear all the assigned template variables.

Returns

\Smarty_Internal_Data

current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining

configLoad()

configLoad(string  $config_file, string|array<mixed,string>|null  $sections = null) : \Smarty_Internal_Data

Load config file data and assign it to the template.

This works identically to the {config_load} function

Parameters

string $config_file

Path to the config file

string|array<mixed,string>|null $sections

Section name or array of section names

Returns

\Smarty_Internal_Data

current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining

getVariable()

getVariable(string  $variable, \Smarty_Internal_Data|null  $_ptr = null, boolean  $search_parents = true, boolean  $error_enable = true) : mixed

Return the contents of an assigned variable.

Parameters

string $variable

the name of the Smarty variable

\Smarty_Internal_Data|null $_ptr

Optional reference to the data object

boolean $search_parents

Whether to search in the parent scope

boolean $error_enable

Whether to raise an error when the variable is not found.

Returns

mixed —

The contents of the variable.

getConfigVariable()

getConfigVariable(string  $variable,   $error_enable = true) : mixed

gets a config variable

Parameters

string $variable

the name of the config variable

$error_enable

Returns

mixed —

the value of the config variable

getStreamVariable()

getStreamVariable(string  $variable) : mixed

gets a stream variable

Parameters

string $variable

the stream of the variable

Returns

mixed —

the value of the stream variable

getConfigVars()

getConfigVars(string|null  $varname = null, boolean  $search_parents = true) : string

Returns a single or all config variables

Parameters

string|null $varname

Variable name or null (to retrieve all)

boolean $search_parents

Whether to search parent scopes

Returns

string —

variable value or or array of variables

clearConfig()

clearConfig(string|null  $varname = null) : \Smarty_Internal_Data

Clears all loaded config variables.

Parameters

string|null $varname

variable name or null

Returns

\Smarty_Internal_Data

current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining

assign_by_ref()

assign_by_ref(string  $tpl_var,   $value) 

wrapper for assign_by_ref

Parameters

string $tpl_var

the template variable name

$value

append_by_ref()

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

wrapper for append_by_ref

Parameters

string $tpl_var

the template variable name

$value
boolean $merge

flag if array elements shall be merged

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, boolean  $cacheable = true, mixed  $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

boolean $cacheable
mixed $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  $object_impl, 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 $object_impl

the referenced PHP object to register

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, boolean  $cacheable = true, mixed  $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

boolean $cacheable
mixed $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, boolean  $cacheable = true) 

Registers compiler function

Parameters

string $function

name of template function

string $function_impl

name of PHP function to register

boolean $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(callable  $function) 

Registers a prefilter function to apply to a template before compiling

Parameters

callable $function

unregister_prefilter()

unregister_prefilter(callable  $function) 

Unregisters a prefilter function

Parameters

callable $function

register_postfilter()

register_postfilter(callable  $function) 

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

Parameters

callable $function

unregister_postfilter()

unregister_postfilter(callable  $function) 

Unregisters a postfilter function

Parameters

callable $function

register_outputfilter()

register_outputfilter(callable  $function) 

Registers an output filter function to apply to a template output

Parameters

callable $function

unregister_outputfilter()

unregister_outputfilter(callable  $function) 

Unregisters an outputfilter function

Parameters

callable $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

is_cached()

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

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

boolean

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

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

trigger_error()

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

trigger Smarty error

Parameters

string $error_msg
integer $error_type

replaceCamelcase()

replaceCamelcase(string  $match) : string

preg_replace callback to convert camelcase getter/setter to underscore property names

Parameters

string $match

match string

Returns

string —

replacemant