Properties

$template_resource

$template_resource : string

Full template resource

Type

string

$strict_mode

$strict_mode : boolean

Flag indicating that the template is running in strict mode

Type

boolean

$smarty

$smarty : \Box\Brainy\Templates\Smarty

Global smarty instance

Type

\Box\Brainy\Templates\Smarty

$compile_id

$compile_id : string

$compile_id

Type

string

$properties

$properties : array

special compiled template properties

Type

array

$required_plugins

$required_plugins : array

required plugins

Type

array

$source

$source : 

Type

$compiled

$compiled : 

Type

Methods

__construct()

__construct(string  $tplResource, \Box\Brainy\Brainy  $brainy, \Box\Brainy\Templates\Template  $parent = null, mixed  $compileID = null, boolean|void  $suppressData = false) 

Create template data object

Some of the global Smarty settings copied to template scope It load the required template resources and cacher plugins

Parameters

string $tplResource

template resource string

\Box\Brainy\Brainy $brainy

Brainy instance

\Box\Brainy\Templates\Template $parent

back pointer to parent object with variables or null

mixed $compileID

compile id or null

boolean|void $suppressData

Prevents data from being copied into the variable scope

assert_is_not_strict()

assert_is_not_strict(string  $reason) : void

Parameters

string $reason

Throws

\Box\Brainy\Exceptions\BrainyStrictModeException

fetch()

fetch(string|void  $template = null, mixed|void  $compile_id = null) : string

Renders and returns a template.

This returns the template output instead of displaying it.

Parameters

string|void $template

the resource handle of the template file or template object

mixed|void $compile_id

compile id to be used with this template

Returns

string —

rendered template output

display()

display(string|null|void  $template = null, string|null|void  $compile_id = 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|null|void $template

the resource handle of the template file or template object

string|null|void $compile_id

compile id to be used with this template

setVariable()

setVariable(string  $var, mixed  $value, integer  $scope = -1) : void

Assigns $value to the variale $var.

Parameters

string $var

the template variable name

mixed $value

the value to assign

integer $scope

the scope to associate with the Smarty_Variable

renderSubTemplate()

renderSubTemplate(string  $template, mixed  $compile_id,   $data, integer  $parent_scope) : void

Template code runtime function to get subtemplate content

Parameters

string $template

the resource handle of the template file

mixed $compile_id

compile id to be used with this template

$data
integer $parent_scope

scope in which {include} should execute

assign()

assign(array|string  $var, mixed|null|void  $value = null, integer|void  $scope = -1) : \Box\Brainy\Templates\TemplateData

Assigns $value to the variable in $var. 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|null|void $value

the value to assign

integer|void $scope

the scope to associate with the Smarty_Variable instance

Returns

\Box\Brainy\Templates\TemplateData

current TemplateData (or Smarty or Template) instance for chaining

assignGlobal()

assignGlobal(string  $varname, mixed  $value = null) : \Box\Brainy\Templates\TemplateData

Assigns a global Smarty variable to the global scope.

Parameters

string $varname

the global variable name

mixed $value

the value to assign

Returns

\Box\Brainy\Templates\TemplateData

current TemplateData (or Smarty or Template) instance for chaining

getTemplateVars()

getTemplateVars(string  $varname = null, \Box\Brainy\Templates\TemplateData  $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

\Box\Brainy\Templates\TemplateData $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>  $varName) : \Box\Brainy\Templates\TemplateData

Clear the given assigned template variable.

Parameters

string|array<mixed,string> $varName

The template variable(s) to clear

Returns

\Box\Brainy\Templates\TemplateData

current TemplateData (or Smarty or Template) instance for chaining

clearAllAssign()

clearAllAssign() : \Box\Brainy\Templates\TemplateData

Clear all the assigned template variables.

Returns

\Box\Brainy\Templates\TemplateData

current TemplateData instance for chaining

getVariable()

getVariable(string  $variable, \Box\Brainy\Templates\TemplateData|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

\Box\Brainy\Templates\TemplateData|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.

cloneDataFrom()

cloneDataFrom(\Box\Brainy\Templates\TemplateData  $source, boolean|void  $override = true) : void

Copies each variable from the source into this object, creating new `Variable` objects along the way.

Parameters

\Box\Brainy\Templates\TemplateData $source
boolean|void $override

Whether to override existing values

applyDataFrom()

applyDataFrom(array  $source, boolean|void  $override = true) : void

Applies all of the data to the current object

Parameters

array $source
boolean|void $override

Whether to override existing values

mustCompile()

mustCompile() : boolean

Returns if the current template must be compiled by the Smarty compiler

It does compare the timestamps of template source and the compiled templates

Returns

boolean —

true if the template must be compiled

compileTemplateSource()

compileTemplateSource() : string

Compiles the template

Returns

string —

The compiled template source

createTemplateCodeFrame()

createTemplateCodeFrame(string  $content = '') : string

Create code frame for compiled and cached templates

Parameters

string $content

optional template content

Returns

string

decodeProperties()

decodeProperties(array  $properties) : boolean

This function is executed automatically when a compiled or cached template file is included

Parameters

array $properties

special template properties

Returns

boolean —

flag if compiled or cache file is valid

getScopePointer()

getScopePointer(integer  $scope) : mixed

Get parent or root of template parent chain

Parameters

integer $scope

pqrent or root scope

Returns

mixed —

object

writeFile()

writeFile(string  $_filepath, string  $_contents, \Box\Brainy\Templates\Smarty  $smarty) : boolean

Writes file in a safe way to disk

Parameters

string $_filepath

complete filepath

string $_contents

file content

\Box\Brainy\Templates\Smarty $smarty

smarty instance

Returns

boolean —

true

assignSingleVar()

assignSingleVar(string  $var, mixed  $value, integer  $scope = -1) : void

Assigns $value to the variale $var.

Parameters

string $var

the template variable name

mixed $value

the value to assign

integer $scope

the scope to associate with the Smarty_Variable