CRM_Core_Smarty
extends CRM_Core_SmartyCompatibility
in package
Table of Contents
Constants
- PRINT_JSON = 'json'
- PRINT_NOFORM = 4
- PRINT_PAGE = 1
- PRINT_PDF = 3
- PRINT_QFKEY = 5
- PRINT_SNIPPET = 2
Properties
- $_singleton : object
- We only need one instance of this object. So we use the singleton pattern and cache the instance in this variable
- $backupFrames : array<string|int, mixed>
- Backup frames.
- $UNDEFINED_VALUE : object
- This is a sentinel-object that indicates an undefined value.
Methods
- addExpectedTabHeaderKeys() : void
- Avoid e-notices on pages with tabs, by ensuring tabHeader items contain the necessary keys
- appendValue() : mixed
- assign_by_ref() : mixed
- Generally Civi mis-uses this for perceived php4 conformance, avoid.
- assignAll() : CRM_Core_Smarty
- callUserFuncArray() : mixed
- Call a permitted function from the Smarty layer.
- clear_assign() : mixed|null|void
- Generally Civi mis-uses this for perceived php4 conformance, avoid.
- clearTemplateVars() : void
- Clear template variables, except session or config.
- ensureVariablesAreAssigned() : void
- Ensure these variables are set to make it easier to access them without e-notice.
- escape() : string
- Smarty escape modifier plugin.
- fetchWith() : bool|mixed|string
- Fetch a template (while using certain variables)
- get_template_vars() : array<string|int, mixed>
- Returns an array containing template variables
- getVersion() : int
- handleSmartyError() : void
- Handle smarty error in one off string.
- load_filter() : mixed
- popScope() : CRM_Core_Smarty
- Remove any values that were previously pushed.
- pushScope() : CRM_Core_Smarty
- Temporarily assign a list of variables.
- register_function() : mixed
- Registers custom function to be used in templates
- register_modifier() : mixed
- Registers modifier to be used in templates
- register_resource() : mixed
- Registers a resource to fetch a template
- registerStringResource() : mixed
- singleton() : CRM_Core_Smarty
- Static instance provider.
- template_exists() : bool
- Checks whether requested template exists.
- getLocale() : string
- Get the locale for translation.
- initialize() : mixed
- isCheckSmartyIsCompiled() : bool
- Get the compile_check value.
Constants
PRINT_JSON
public
mixed
PRINT_JSON
= 'json'
PRINT_NOFORM
public
mixed
PRINT_NOFORM
= 4
PRINT_PAGE
public
mixed
PRINT_PAGE
= 1
PRINT_PDF
public
mixed
PRINT_PDF
= 3
PRINT_QFKEY
public
mixed
PRINT_QFKEY
= 5
PRINT_SNIPPET
public
mixed
PRINT_SNIPPET
= 2
Properties
$_singleton
We only need one instance of this object. So we use the singleton pattern and cache the instance in this variable
private
static object
$_singleton
= \NULL
$backupFrames
Backup frames.
private
array<string|int, mixed>
$backupFrames
= []
A list of variables ot save temporarily in format (string $name => mixed $value).
$UNDEFINED_VALUE
This is a sentinel-object that indicates an undefined value.
private
static object
$UNDEFINED_VALUE
It lacks any substantive content; but it has unique identity that cannot be mistaken for
organic values like null
, string
, false
, or similar.
Methods
addExpectedTabHeaderKeys()
Avoid e-notices on pages with tabs, by ensuring tabHeader items contain the necessary keys
public
addExpectedTabHeaderKeys() : void
appendValue()
public
appendValue(string $name, mixed $value) : mixed
Parameters
- $name : string
- $value : mixed
assign_by_ref()
Generally Civi mis-uses this for perceived php4 conformance, avoid.
public
assign_by_ref(string $tpl_var, mixed &$value) : mixed
Parameters
- $tpl_var : string
- $value : mixed
assignAll()
public
assignAll(array<string|int, mixed> $vars) : CRM_Core_Smarty
Parameters
- $vars : array<string|int, mixed>
-
(string $name => mixed $value).
Return values
CRM_Core_SmartycallUserFuncArray()
Call a permitted function from the Smarty layer.
public
static callUserFuncArray(callable $callable, mixed ...$args) : mixed
In general calling functions from the Smarty layer is being made stricter in Smarty - they need to be registered.
We can't quite kill off call_user_func from the smarty layer yet but we can deprecate using it to call anything other than the 3 known patterns. In Smarty5 this will hard-fail, which is OK as Smarty5 is being phased in and can err on the side of strictness, at least for now.
Parameters
- $callable : callable
- $args : mixed
Tags
clear_assign()
Generally Civi mis-uses this for perceived php4 conformance, avoid.
public
clear_assign(string $tpl_var) : mixed|null|void
Parameters
- $tpl_var : string
Return values
mixed|null|voidclearTemplateVars()
Clear template variables, except session or config.
public
clearTemplateVars() : void
Also the debugging variable because during test runs initialize() is only called once at the start but the var gets indirectly accessed by a couple tests that test forms.
ensureVariablesAreAssigned()
Ensure these variables are set to make it easier to access them without e-notice.
public
ensureVariablesAreAssigned(array<string|int, mixed> $variables) : void
Parameters
- $variables : array<string|int, mixed>
escape()
Smarty escape modifier plugin.
public
static escape(string $string[, string $esc_type = 'html' ][, string $char_set = 'UTF-8' ]) : string
This replaces the core smarty modifier and basically does a lot of early-returning before calling the core function.
It early returns on patterns that are common 'no-escape' patterns in CiviCRM - this list can be honed over time.
It also logs anything that is actually escaped. Since this only kicks in when CIVICRM_SMARTY_DEFAULT_ESCAPE is defined it is ok to be aggressive about logging as we mostly care about developers using it at this stage.
Note we don't actually use 'htmlall' anywhere in our tpl layer yet so anything coming in with this be happening because of the default modifier.
Also note the right way to opt a field OUT of escaping is
{$fieldName nofilter}
This should be used for fields with known html AND for fields where
we are doing empty or isset checks - as otherwise the value is passed for
escaping first so you still get an enotice for 'empty' or a fatal for 'isset'
Type: modifier
Name: escape
Purpose: Escape the string according to escapement type
Parameters
- $string : string
- $esc_type : string = 'html'
- $char_set : string = 'UTF-8'
Tags
Return values
stringfetchWith()
Fetch a template (while using certain variables)
public
fetchWith(string $resource_name, array<string|int, mixed> $vars) : bool|mixed|string
Parameters
- $resource_name : string
- $vars : array<string|int, mixed>
-
(string $name => mixed $value) variables to export to Smarty.
Tags
Return values
bool|mixed|stringget_template_vars()
Returns an array containing template variables
public
& get_template_vars([string $name = NULL ]) : array<string|int, mixed>
since 5.69 will be removed around 5.79
Parameters
- $name : string = NULL
Return values
array<string|int, mixed>getVersion()
public
getVersion() : int
Return values
inthandleSmartyError()
Handle smarty error in one off string.
public
handleSmartyError(int $errorNumber, string $errorMessage) : void
Parameters
- $errorNumber : int
- $errorMessage : string
Tags
load_filter()
public
load_filter(string $type, string $name) : mixed
Parameters
- $type : string
- $name : string
Tags
popScope()
Remove any values that were previously pushed.
public
popScope() : CRM_Core_Smarty
Tags
Return values
CRM_Core_SmartypushScope()
Temporarily assign a list of variables.
public
pushScope(array<string|int, mixed> $vars) : CRM_Core_Smarty
$smarty->pushScope(array(
'first_name' => 'Alice',
'last_name' => 'roberts',
));
$html = $smarty->fetch('view-contact.tpl');
$smarty->popScope();
Parameters
- $vars : array<string|int, mixed>
-
(string $name => mixed $value).
Tags
Return values
CRM_Core_Smartyregister_function()
Registers custom function to be used in templates
public
register_function(string $function, string $function_impl[, bool $cacheable = TRUE ][, null $cache_attrs = NULL ]) : mixed
Parameters
- $function : string
-
the name of the template function
- $function_impl : string
-
the name of the PHP function to register
- $cacheable : bool = TRUE
- $cache_attrs : null = NULL
Tags
register_modifier()
Registers modifier to be used in templates
public
register_modifier(string $modifier, string $modifier_impl) : mixed
Parameters
- $modifier : string
-
name of template modifier
- $modifier_impl : string
-
name of PHP function to register
register_resource()
Registers a resource to fetch a template
public
register_resource(string $type, array<string|int, mixed> $functions) : mixed
Parameters
- $type : string
-
name of resource
- $functions : array<string|int, mixed>
-
array of functions to handle resource
registerStringResource()
public
static registerStringResource() : mixed
singleton()
Static instance provider.
public
static & singleton() : CRM_Core_Smarty
Method providing static instance of SmartTemplate, as in Singleton pattern.
Return values
CRM_Core_Smartytemplate_exists()
Checks whether requested template exists.
public
template_exists(string $tpl_file) : bool
Parameters
- $tpl_file : string
Tags
Return values
boolgetLocale()
Get the locale for translation.
private
getLocale() : string
Return values
stringinitialize()
private
initialize() : mixed
Tags
isCheckSmartyIsCompiled()
Get the compile_check value.
private
isCheckSmartyIsCompiled() : bool