Skip to content

Smarty

This is the main Smarty class

Constants

Constant Visibility Type Value
SMARTY_VERSION public '4.5.4'
SCOPE_LOCAL public 1
SCOPE_PARENT public 2
SCOPE_TPL_ROOT public 4
SCOPE_ROOT public 8
SCOPE_SMARTY public 16
SCOPE_GLOBAL public 32
CACHING_OFF public 0
CACHING_LIFETIME_CURRENT public 1
CACHING_LIFETIME_SAVED public 2
CLEAR_EXPIRED public -1
COMPILECHECK_OFF public 0
COMPILECHECK_ON public 1
COMPILECHECK_CACHEMISS public 2
DEBUG_OFF public 0
DEBUG_ON public 1
DEBUG_INDIVIDUAL public 2
FILTER_POST public 'post'
FILTER_PRE public 'pre'
FILTER_OUTPUT public 'output'
FILTER_VARIABLE public 'variable'
PLUGIN_FUNCTION public 'function'
PLUGIN_BLOCK public 'block'
PLUGIN_COMPILER public 'compiler'
PLUGIN_MODIFIER public 'modifier'
PLUGIN_MODIFIERCOMPILER public 'modifiercompiler'

Properties

global_tpl_vars

assigned global tpl vars

public static $global_tpl_vars
  • This property is static.

_MBSTRING

Flag denoting if Multibyte String functions are available

public static $_MBSTRING
  • This property is static.

_CHARSET

The character set to adhere to (e.g. "UTF-8")

public static $_CHARSET
  • This property is static.

_DATE_FORMAT

The date format to be used internally (accepts date() and strftime())

public static $_DATE_FORMAT
  • This property is static.

_UTF8_MODIFIER

Flag denoting if PCRE should run in UTF-8 mode

public static $_UTF8_MODIFIER
  • This property is static.

_IS_WINDOWS

Flag denoting if operating system is windows

public static $_IS_WINDOWS
  • This property is static.

auto_literal

auto literal on delimiters with whitespace

public bool $auto_literal

error_unassigned

display error on not assigned variables

public bool $error_unassigned

use_include_path

look up relative file path in include_path

public bool $use_include_path

_templateDirNormalized

flag if template_dir is normalized

public bool $_templateDirNormalized

_joined_template_dir

joined template directory string used in cache keys

public string $_joined_template_dir

_configDirNormalized

flag if config_dir is normalized

public bool $_configDirNormalized

_joined_config_dir

joined config directory string used in cache keys

public string $_joined_config_dir

default_template_handler_func

default template handler

public callable $default_template_handler_func

default_config_handler_func

default config handler

public callable $default_config_handler_func

default_plugin_handler_func

default plugin handler

public callable $default_plugin_handler_func

_compileDirNormalized

flag if template_dir is normalized

public bool $_compileDirNormalized

_pluginsDirNormalized

flag if plugins_dir is normalized

public bool $_pluginsDirNormalized

_cacheDirNormalized

flag if template_dir is normalized

public bool $_cacheDirNormalized

force_compile

force template compiling?

public bool $force_compile

use_sub_dirs

use sub dirs for compiled/cached files?

public bool $use_sub_dirs

allow_ambiguous_resources

allow ambiguous resources (that are made unique by the resource handler)

public bool $allow_ambiguous_resources

merge_compiled_includes

merge compiled includes

public bool $merge_compiled_includes

extends_recursion

public $extends_recursion

force_cache

force cache file creation

public bool $force_cache

left_delimiter

template left-delimiter

public string $left_delimiter

right_delimiter

template right-delimiter

public string $right_delimiter

literals

array of strings which shall be treated as literal by compiler

public array $literals

security_class

class name This should be instance of Smarty_Security.

public string $security_class

See Also:

  • \Smarty_Security -

security_policy

implementation of security class

public \Smarty_Security $security_policy

allow_php_templates

controls if the php template file resource is allowed

public bool $allow_php_templates

debugging

debug mode Setting this to true enables the debug-console.

public bool $debugging

debugging_ctrl

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

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

smarty_debug_id

Name of debugging URL-param.

public string $smarty_debug_id

Only used when $debugging_ctrl is set to 'URL'. The name of the URL-parameter that activates debugging.


debug_tpl

Path of debug template.

public string $debug_tpl

error_reporting

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

public int $error_reporting

config_overwrite

Controls whether variables with the same name overwrite each other.

public bool $config_overwrite

config_booleanize

Controls whether config values of on/true/yes and off/false/no get converted to boolean.

public bool $config_booleanize

config_read_hidden

Controls whether hidden config sections/vars are read from the file.

public bool $config_read_hidden

compile_locking

locking concurrent compiles

public bool $compile_locking

cache_locking

Controls whether cache resources should use locking mechanism

public bool $cache_locking

locking_timeout

seconds to wait for acquiring a lock before ignoring the write lock

public float $locking_timeout

default_resource_type

resource type used if none given Must be an valid key of $registered_resources.

public string $default_resource_type

caching_type

caching type Must be an element of $cache_resource_types.

public string $caching_type

default_config_type

config type

public string $default_config_type

cache_modified_check

check If-Modified-Since headers

public bool $cache_modified_check

registered_plugins

registered plugins

public array $registered_plugins

registered_objects

registered objects

public array $registered_objects

registered_classes

registered classes

public array $registered_classes

registered_filters

registered filters

public array $registered_filters

registered_resources

registered resources

public array $registered_resources

registered_cache_resources

registered cache resources

public array $registered_cache_resources

autoload_filters

autoload filter

public array $autoload_filters

default_modifiers

default modifier

public array $default_modifiers

escape_html

autoescape variable output

public bool $escape_html

start_time

start time for execution time calculation

public int $start_time

_current_file

required by the compiler for BC

public string $_current_file

_parserdebug

internal flag to enable parser debugging

public bool $_parserdebug

_objType

This object type (Smarty = 1, template = 2, data = 4)

public int $_objType

_debug

Debug object

public \Smarty_Internal_Debug $_debug

template_dir

template directory

protected array $template_dir

_processedTemplateDir

flags for normalized template directory entries

protected array $_processedTemplateDir

config_dir

config directory

protected array $config_dir

_processedConfigDir

flags for normalized template directory entries

protected array $_processedConfigDir

compile_dir

compile directory

protected string $compile_dir

plugins_dir

plugins directory

protected array $plugins_dir

cache_dir

cache directory

protected string $cache_dir

obsoleteProperties

removed properties

protected string[] $obsoleteProperties

accessMap

List of private properties which will call getter/setter on a direct access

protected string[] $accessMap

isMutingUndefinedOrNullWarnings

PHP7 Compatibility mode

private bool $isMutingUndefinedOrNullWarnings

Methods

__construct

Initialize new Smarty object

public __construct(): mixed

templateExists

Check if a template resource exists

public templateExists(string $resource_name): bool

Parameters:

Parameter Type Description
$resource_name string template name

Return Value:

status

Throws:


enableSecurity

Loads security class and enables security

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

Parameters:

Parameter Type Description
$security_class string|\Smarty_Security if a string is used, it must be class-name

Return Value:

current Smarty instance for chaining

Throws:


disableSecurity

Disable security

public disableSecurity(): \Smarty

Return Value:

current Smarty instance for chaining


addTemplateDir

Add template directory(s)

public addTemplateDir(string|array $template_dir, string $key = null, bool $isConfig = false): \Smarty

Parameters:

Parameter Type Description
$template_dir string|array directory(s) of template sources
$key string of the array element to assign the template dir to
$isConfig bool true for config_dir

Return Value:

current Smarty instance for chaining


getTemplateDir

Get template directories

public getTemplateDir(mixed $index = null, bool $isConfig = false): array|string

Parameters:

Parameter Type Description
$index mixed index of directory to get, null to get all
$isConfig bool true for config_dir

Return Value:

list of template directories, or directory of $index


setTemplateDir

Set template directory

public setTemplateDir(string|array $template_dir, bool $isConfig = false): \Smarty

Parameters:

Parameter Type Description
$template_dir string|array directory(s) of template sources
$isConfig bool true for config_dir

Return Value:

current Smarty instance for chaining


addConfigDir

Add config directory(s)

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

Parameters:

Parameter Type Description
$config_dir string|array directory(s) of config sources
$key mixed key of the array element to assign the config dir to

Return Value:

current Smarty instance for chaining


getConfigDir

Get config directory

public getConfigDir(mixed $index = null): array

Parameters:

Parameter Type Description
$index mixed index of directory to get, null to get all

Return Value:

configuration directory


setConfigDir

Set config directory

public setConfigDir(mixed $config_dir): \Smarty

Parameters:

Parameter Type Description
$config_dir mixed

Return Value:

current Smarty instance for chaining


addPluginsDir

Adds directory of plugin files

public addPluginsDir(null|array|string $plugins_dir): \Smarty

Parameters:

Parameter Type Description
$plugins_dir null|array|string

Return Value:

current Smarty instance for chaining


getPluginsDir

Get plugin directories

public getPluginsDir(): array

Return Value:

list of plugin directories


setPluginsDir

Set plugins directory

public setPluginsDir(string|array $plugins_dir): \Smarty

Parameters:

Parameter Type Description
$plugins_dir string|array directory(s) of plugins

Return Value:

current Smarty instance for chaining


getCompileDir

Get compiled directory

public getCompileDir(): string

Return Value:

path to compiled templates


setCompileDir

public setCompileDir(string $compile_dir): \Smarty

Parameters:

Parameter Type Description
$compile_dir string directory to store compiled templates in

Return Value:

current Smarty instance for chaining


getCacheDir

Get cache directory

public getCacheDir(): string

Return Value:

path of cache directory


setCacheDir

Set cache directory

public setCacheDir(string $cache_dir): \Smarty

Parameters:

Parameter Type Description
$cache_dir string directory to store cached templates in

Return Value:

current Smarty instance for chaining


createTemplate

creates a template object

public createTemplate(string $template, mixed $cache_id = null, mixed $compile_id = null, object $parent = null, bool $do_clone = true): \Smarty_Internal_Template

Parameters:

Parameter Type Description
$template string the resource handle of the template file
$cache_id mixed cache id to be used with this template
$compile_id mixed compile id to be used with this template
$parent object next higher level of Smarty variables
$do_clone bool flag is Smarty object shall be cloned

Return Value:

template object

Throws:


loadPlugin

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

public loadPlugin(string $plugin_name, bool $check = true): string|bool

Parameters:

Parameter Type Description
$plugin_name string class plugin name to load
$check bool check if already loaded

Return Value:

filepath of loaded file or false

Throws:


_getTemplateId

Get unique template id

public _getTemplateId(string $template_name, null|mixed $cache_id = null, null|mixed $compile_id = null, null $caching = null, \Smarty_Internal_Template $template = null): string

Parameters:

Parameter Type Description
$template_name string
$cache_id null|mixed
$compile_id null|mixed
$caching null
$template \Smarty_Internal_Template

Throws:


_realpath

Normalize path - remove /./ and /../ - make it absolute if required

public _realpath(string $path, bool $realpath = null): string

Parameters:

Parameter Type Description
$path string file path
$realpath bool if true - convert to absolute
false - convert to relative
null - keep as it is but
remove /./ /../

_clearTemplateCache

Empty template objects cache

public _clearTemplateCache(): mixed

setUseSubDirs

public setUseSubDirs(bool $use_sub_dirs): mixed

Parameters:

Parameter Type Description
$use_sub_dirs bool

setErrorReporting

public setErrorReporting(int $error_reporting): mixed

Parameters:

Parameter Type Description
$error_reporting int

setEscapeHtml

public setEscapeHtml(bool $escape_html): mixed

Parameters:

Parameter Type Description
$escape_html bool

getAutoLiteral

Return auto_literal flag

public getAutoLiteral(): bool

setAutoLiteral

Set auto_literal flag

public setAutoLiteral(bool $auto_literal = true): mixed

Parameters:

Parameter Type Description
$auto_literal bool

setForceCompile

public setForceCompile(bool $force_compile): mixed

Parameters:

Parameter Type Description
$force_compile bool

setMergeCompiledIncludes

public setMergeCompiledIncludes(bool $merge_compiled_includes): mixed

Parameters:

Parameter Type Description
$merge_compiled_includes bool

getLeftDelimiter

Get left delimiter

public getLeftDelimiter(): string

setLeftDelimiter

Set left delimiter

public setLeftDelimiter(string $left_delimiter): mixed

Parameters:

Parameter Type Description
$left_delimiter string

getRightDelimiter

Get right delimiter

public getRightDelimiter(): string

Return Value:

$right_delimiter


setRightDelimiter

Set right delimiter

public setRightDelimiter(mixed $right_delimiter): mixed

Parameters:

Parameter Type Description
$right_delimiter mixed

setDebugging

public setDebugging(bool $debugging): mixed

Parameters:

Parameter Type Description
$debugging bool

setConfigOverwrite

public setConfigOverwrite(bool $config_overwrite): mixed

Parameters:

Parameter Type Description
$config_overwrite bool

setConfigBooleanize

public setConfigBooleanize(bool $config_booleanize): mixed

Parameters:

Parameter Type Description
$config_booleanize bool

setConfigReadHidden

public setConfigReadHidden(bool $config_read_hidden): mixed

Parameters:

Parameter Type Description
$config_read_hidden bool

setCompileLocking

public setCompileLocking(bool $compile_locking): mixed

Parameters:

Parameter Type Description
$compile_locking bool

setDefaultResourceType

public setDefaultResourceType(string $default_resource_type): mixed

Parameters:

Parameter Type Description
$default_resource_type string

setCachingType

public setCachingType(string $caching_type): mixed

Parameters:

Parameter Type Description
$caching_type string

testInstall

Test install

public testInstall(null& $errors = null): mixed

Parameters:

Parameter Type Description
$errors null

_getSmartyObj

Get Smarty object

public _getSmartyObj(): \Smarty

__get

<> Generic getter.

public __get(string $name): mixed

Calls the appropriate getter function. Issues an E_USER_NOTICE if no valid getter is found.

Parameters:

Parameter Type Description
$name string property name

__set

<> Generic setter.

public __set(string $name, mixed $value): mixed

Calls the appropriate setter function. Issues an E_USER_NOTICE if no valid setter is found.

Parameters:

Parameter Type Description
$name string property name
$value mixed parameter passed to setter

_normalizeDir

Normalize and set directory string

private _normalizeDir(string $dirName, string $dir): mixed

Parameters:

Parameter Type Description
$dirName string cache_dir or compile_dir
$dir string filepath of folder

_normalizeTemplateConfig

Normalize template_dir or config_dir

private _normalizeTemplateConfig(bool $isConfig): mixed

Parameters:

Parameter Type Description
$isConfig bool true for config_dir

muteUndefinedOrNullWarnings

Mutes errors for "undefined index", "undefined array key" and "trying to read property of null".

public muteUndefinedOrNullWarnings(): void

isMutingUndefinedOrNullWarnings

Indicates if Smarty will mute errors for "undefined index", "undefined array key" and "trying to read property of null".

public isMutingUndefinedOrNullWarnings(): bool

Inherited methods

__construct

Smarty_Internal_Data constructor.

public __construct(): mixed

Install extension handler


assign

assigns a Smarty variable

public assign(array|string $tpl_var, mixed $value = null, bool $nocache = false): \Smarty_Internal_Data

Parameters:

Parameter Type Description
$tpl_var array|string the template variable name(s)
$value mixed the value to assign
$nocache bool if true any output of this variable will be not cached

Return Value:

current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining


append

appends values to template variables

public append(array|string $tpl_var, mixed $value = null, bool $merge = false, bool $nocache = false): \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty

Parameters:

Parameter Type Description
$tpl_var array|string the template variable name(s)
$value mixed the value to append
$merge bool flag if array elements shall be merged
$nocache bool if true any output of this variable will
be not cached

See Also:

  • https://www.smarty.net/docs/en/api.append.tpl -

assignGlobal

assigns a global Smarty variable

public assignGlobal(string $varName, mixed $value = null, bool $nocache = false): \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty

Parameters:

Parameter Type Description
$varName string the global variable name
$value mixed the value to assign
$nocache bool if true any output of this variable will be not cached

appendByRef

appends values to template variables by reference

public appendByRef(string $tpl_var, mixed& $value, bool $merge = false): \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty

Parameters:

Parameter Type Description
$tpl_var string the template variable name
$value mixed the referenced value to append
$merge bool flag if array elements shall be merged

assignByRef

assigns values to template variables by reference

public assignByRef(string $tpl_var, mixed& $value, bool $nocache = false): \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty

Parameters:

Parameter Type Description
$tpl_var string the template variable name
$value mixed
$nocache bool if true any output of this variable will be not cached

getTemplateVars

Returns a single or all template variables

public getTemplateVars(string $varName = null, \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $_ptr = null, bool $searchParents = true): mixed

Parameters:

Parameter Type Description
$varName string variable name or null
$_ptr \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty optional pointer to data object
$searchParents bool include parent templates?

Return Value:

variable value or or array of variables

See Also:

  • https://www.smarty.net/docs/en/api.get.template.vars.tpl -

_mergeVars

Follow the parent chain an merge template and config variables

public _mergeVars(\Smarty_Internal_Data|null $data = null): mixed

Parameters:

Parameter Type Description
$data \Smarty_Internal_Data|null

_isDataObj

Return true if this instance is a Data obj

public _isDataObj(): bool

_isTplObj

Return true if this instance is a template obj

public _isTplObj(): bool

_isSmartyObj

Return true if this instance is a Smarty obj

public _isSmartyObj(): bool

_getSmartyObj

Get Smarty object

public _getSmartyObj(): \Smarty

__call

Handle unknown class methods

public __call(string $name, array $args): mixed

Parameters:

Parameter Type Description
$name string unknown method-name
$args array argument array

fetch

fetches a rendered Smarty template

public fetch(string $template = null, mixed $cache_id = null, mixed $compile_id = null, object $parent = null): string

Parameters:

Parameter Type Description
$template string the resource handle of the template file or template object
$cache_id mixed cache id to be used with this template
$compile_id mixed compile id to be used with this template
$parent object next higher level of Smarty variables

Return Value:

rendered template output

Throws:


display

displays a Smarty template

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

Parameters:

Parameter Type Description
$template string the resource handle of the template file or template object
$cache_id mixed cache id to be used with this template
$compile_id mixed compile id to be used with this template
$parent object next higher level of Smarty variables

Throws:


isCached

test if cache is valid

public isCached(null|string|\Smarty_Internal_Template $template = null, mixed $cache_id = null, mixed $compile_id = null, object $parent = null): bool

Parameters:

Parameter Type Description
$template null|string|\Smarty_Internal_Template the resource handle of the template file or template
object
$cache_id mixed cache id to be used with this template
$compile_id mixed compile id to be used with this template
$parent object next higher level of Smarty variables

Return Value:

cache status

Throws:

See Also:

  • https://www.smarty.net/docs/en/api.is.cached.tpl -

_execute

fetches a rendered Smarty template

private _execute(string $template, mixed $cache_id, mixed $compile_id, object $parent, string $function): mixed

Parameters:

Parameter Type Description
$template string the resource handle of the template file or template object
$cache_id mixed cache id to be used with this template
$compile_id mixed compile id to be used with this template
$parent object next higher level of Smarty variables
$function string function type 0 = fetch, 1 = display, 2 = isCache

Throws:


registerPlugin

Registers plugin to be used in templates

public registerPlugin(string $type, string $name, callable $callback, bool $cacheable = true, mixed $cache_attr = null): \Smarty|\Smarty_Internal_Template

Parameters:

Parameter Type Description
$type string plugin type
$name string name of template tag
$callback callable PHP callback to register
$cacheable bool if true (default) this function is cache able
$cache_attr mixed caching attributes if any

Throws:

See Also:

  • https://www.smarty.net/docs/en/api.register.plugin.tpl -

loadFilter

load a filter of specified type and name

public loadFilter(string $type, string $name): bool

Parameters:

Parameter Type Description
$type string filter type
$name string filter name

Throws:

See Also:

  • https://www.smarty.net/docs/en/api.load.filter.tpl -

registerFilter

Registers a filter function

public registerFilter(string $type, callable $callback, string|null $name = null): \Smarty|\Smarty_Internal_Template

Parameters:

Parameter Type Description
$type string filter type
$callback callable
$name string|null optional filter name

Throws:

See Also:

  • https://www.smarty.net/docs/en/api.register.filter.tpl -

registerObject

Registers object to be used in templates

public registerObject(string $object_name, object $object, array $allowed_methods_properties = array(), bool $format = true, array $block_methods = array()): \Smarty|\Smarty_Internal_Template

Parameters:

Parameter Type Description
$object_name string
$object object the referenced PHP object to register
$allowed_methods_properties array list of allowed methods (empty = all)
$format bool smarty argument format, else traditional
$block_methods array list of block-methods

Throws:

See Also:

  • https://www.smarty.net/docs/en/api.register.object.tpl -

setCompileCheck

public setCompileCheck(int $compile_check): mixed

Parameters:

Parameter Type Description
$compile_check int

setCaching

public setCaching(int $caching): mixed

Parameters:

Parameter Type Description
$caching int

setCacheLifetime

public setCacheLifetime(int $cache_lifetime): mixed

Parameters:

Parameter Type Description
$cache_lifetime int

setCompileId

public setCompileId(string $compile_id): mixed

Parameters:

Parameter Type Description
$compile_id string

setCacheId

public setCacheId(string $cache_id): mixed

Parameters:

Parameter Type Description
$cache_id string


Automatically generated on 2025-03-18