@api
- Since
- 100.0.2
Definition at line 16 of file Template.php.
◆ __construct()
- Parameters
-
\Magento\Framework\Stdlib\StringUtils | $string | |
array | $variables | |
Definition at line 69 of file Template.php.
setVariables(array $variables)
◆ addAfterFilterCallback()
addAfterFilterCallback |
( |
callable |
$afterFilterCallback | ) |
|
Adds a callback to run after main filtering has happened. Callback must accept a single argument and return a string of the processed value.
- Parameters
-
callable | $afterFilterCallback | |
- Returns
- $this
Definition at line 238 of file Template.php.
241 if (in_array($afterFilterCallback, $this->afterFilterCallbacks)) {
245 $this->afterFilterCallbacks[] = $afterFilterCallback;
◆ afterFilter()
Runs callbacks that have been added to filter content after directive processing is finished.
- Parameters
-
- Returns
- string
Definition at line 220 of file Template.php.
222 foreach ($this->afterFilterCallbacks as $callback) {
call_user_func($callable, $param)
resetAfterFilterCallbacks()
◆ dependDirective()
dependDirective |
( |
|
$construction | ) |
|
- Parameters
-
- Returns
- string
Definition at line 309 of file Template.php.
311 if (count($this->templateVars) == 0) {
313 return $construction[0];
316 if ($this->
getVariable($construction[1],
'') ==
'') {
319 return $construction[2];
getVariable($value, $default='{no_value_defined}')
◆ filter()
Filter the string as template.
- Parameters
-
- Returns
- string
- Exceptions
-
Implements Zend_Filter_Interface.
Definition at line 119 of file Template.php.
123 self::CONSTRUCTION_DEPEND_PATTERN =>
'dependDirective',
124 self::CONSTRUCTION_IF_PATTERN =>
'ifDirective',
125 self::CONSTRUCTION_TEMPLATE_PATTERN =>
'templateDirective',
127 if (preg_match_all(
$pattern,
$value, $constructions, PREG_SET_ORDER)) {
128 foreach ($constructions as $construction) {
129 $callback = [$this, $directive];
130 if (!is_callable($callback)) {
135 }
catch (\Exception $e) {
138 $value = str_replace($construction[0], $replacedValue,
$value);
145 if (preg_match_all(self::CONSTRUCTION_PATTERN,
$value, $constructions, PREG_SET_ORDER)) {
146 foreach ($constructions as $construction) {
147 $callback = [$this, $construction[1] .
'Directive'];
148 if (!is_callable($callback)) {
153 }
catch (\Exception $e) {
156 $value = str_replace($construction[0], $replacedValue,
$value);
call_user_func($callable, $param)
◆ getParameters()
Return associative array of parameters.
- Parameters
-
string | $value | raw parameters |
- Returns
- array
Definition at line 349 of file Template.php.
351 $tokenizer =
new Template\Tokenizer\Parameter();
352 $tokenizer->setString(
$value);
353 $params = $tokenizer->tokenize();
355 if (substr(
$value, 0, 1) ===
'$') {
getVariable($value, $default='{no_value_defined}')
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
◆ getStackArgs()
Loops over a set of stack args to process variables into array argument values
- Parameters
-
- Returns
- array
Definition at line 434 of file Template.php.
elseif(isset( $params[ 'redirect_parent']))
getVariable($value, $default='{no_value_defined}')
◆ getTemplateProcessor()
Sets the processor for template directive.
- Returns
- callable|null
Definition at line 106 of file Template.php.
108 return is_callable($this->templateProcessor) ? $this->templateProcessor :
null;
◆ getVariable()
getVariable |
( |
|
$value, |
|
|
|
$default = '{no_value_defined}' |
|
) |
| |
|
protected |
Return variable value for var construction
- Parameters
-
string | $value | raw parameters |
string | $default | default value |
- Returns
- string @SuppressWarnings(PHPMD.CyclomaticComplexity)
Definition at line 370 of file Template.php.
372 \Magento\Framework\Profiler::start('email_template_processing_variables
'); 373 $tokenizer = new Template\Tokenizer\Variable(); 374 $tokenizer->setString($value); 375 $stackVars = $tokenizer->tokenize(); 378 for ($i = 0; $i < count($stackVars); $i++) { 379 if ($i == 0 && isset($this->templateVars[$stackVars[$i]['name']])) { 380 // Getting of template value 381 $stackVars[$i]['variable
'] = & $this->templateVars[$stackVars[$i]['name']]; 382 } elseif (isset($stackVars[$i - 1]['variable
']) 383 && $stackVars[$i - 1]['variable
'] instanceof \Magento\Framework\DataObject 385 // If data object calling methods or getting properties 386 if ($stackVars[$i]['type
'] == 'property') { 387 $caller = 'get' . $this->string->upperCaseWords($stackVars[$i]['name'], '_
', ''); 388 $stackVars[$i]['variable
'] = method_exists( 389 $stackVars[$i - 1]['variable
'], 391 ) ? $stackVars[$i - 1]['variable
']->{$caller}() : $stackVars[$i - 1]['variable
']->getData( 392 $stackVars[$i]['name'] 394 } elseif ($stackVars[$i]['type
'] == 'method
') { 395 // Calling of data object method 396 if (method_exists($stackVars[$i - 1]['variable
'], $stackVars[$i]['name']) 397 || substr($stackVars[$i]['name'], 0, 3) == 'get' 399 $stackVars[$i]['args
'] = $this->getStackArgs($stackVars[$i]['args
']); 400 $stackVars[$i]['variable
'] = call_user_func_array( 401 [$stackVars[$i - 1]['variable
'], $stackVars[$i]['name']], 402 $stackVars[$i]['args
'] 407 } elseif (isset($stackVars[$i - 1]['variable
']) && $stackVars[$i]['type
'] == 'method
') { 408 // Calling object methods 409 if (method_exists($stackVars[$i - 1]['variable
'], $stackVars[$i]['name'])) { 410 $stackVars[$i]['args
'] = $this->getStackArgs($stackVars[$i]['args
']); 411 $stackVars[$i]['variable
'] = call_user_func_array( 412 [$stackVars[$i - 1]['variable
'], $stackVars[$i]['name']], 413 $stackVars[$i]['args
'] 420 if (isset($stackVars[$last]['variable
'])) { 421 // If value for construction exists set it 422 $result = $stackVars[$last]['variable
']; 424 \Magento\Framework\Profiler::stop('email_template_processing_variables
');
◆ ifDirective()
ifDirective |
( |
|
$construction | ) |
|
- Parameters
-
- Returns
- string
Definition at line 327 of file Template.php.
329 if (count($this->templateVars) == 0) {
330 return $construction[0];
333 if ($this->
getVariable($construction[1],
'') ==
'') {
334 if (isset($construction[3]) && isset($construction[4])) {
335 return $construction[4];
339 return $construction[2];
getVariable($value, $default='{no_value_defined}')
◆ resetAfterFilterCallbacks()
resetAfterFilterCallbacks |
( |
| ) |
|
|
protected |
Resets the after filter callbacks
- Returns
- $this
Definition at line 254 of file Template.php.
256 $this->afterFilterCallbacks = [];
◆ setTemplateProcessor()
setTemplateProcessor |
( |
callable |
$callback | ) |
|
Sets the processor for template directive.
- Parameters
-
callable | $callback | it must return string |
- Returns
- $this
Definition at line 95 of file Template.php.
97 $this->templateProcessor = $callback;
◆ setVariables()
setVariables |
( |
array |
$variables | ) |
|
Sets template variables that's can be called through {var ...} statement
- Parameters
-
- Returns
- \Magento\Framework\Filter\Template
Definition at line 81 of file Template.php.
if(!isset($_GET['name'])) $name
◆ templateDirective()
templateDirective |
( |
|
$construction | ) |
|
Allows templates to be included inside other templates
Usage:
{{template config_path="<PATH>"}}
<PATH> equals the XPATH to the system configuration value that contains the value of the template. This directive is useful to include things like a global header/footer.
- Parameters
-
- Returns
- mixed
Definition at line 288 of file Template.php.
291 $templateParameters = $this->
getParameters($construction[2]);
294 $replacedValue =
'{Error in template processing}';
297 $configPath = $templateParameters[
'config_path'];
298 unset($templateParameters[
'config_path']);
299 $templateParameters = array_merge_recursive($templateParameters, $this->templateVars);
302 return $replacedValue;
call_user_func($callable, $param)
◆ varDirective()
varDirective |
( |
|
$construction | ) |
|
- Parameters
-
- Returns
- string
Definition at line 264 of file Template.php.
266 if (count($this->templateVars) == 0) {
268 return $construction[0];
271 $replacedValue = $this->
getVariable($construction[2],
'');
272 return $replacedValue;
getVariable($value, $default='{no_value_defined}')
◆ $string
◆ $templateProcessor
$templateProcessor = null |
|
protected |
◆ $templateVars
◆ CONSTRUCTION_DEPEND_PATTERN
const CONSTRUCTION_DEPEND_PATTERN = '/{{depend\s*(.*?)}}(.*?){{\\/depend\s*}}/si' |
Construction depend
regular expression
Definition at line 26 of file Template.php.
◆ CONSTRUCTION_IF_PATTERN
const CONSTRUCTION_IF_PATTERN = '/{{if\s*(.*?)}}(.*?)({{else}}(.*?))?{{\\/if\s*}}/si' |
Construction if
regular expression
Definition at line 31 of file Template.php.
◆ CONSTRUCTION_PATTERN
const CONSTRUCTION_PATTERN = '/{{([a-z]{0,10})(.*?)}}/si' |
Construction regular expression
Definition at line 21 of file Template.php.
◆ CONSTRUCTION_TEMPLATE_PATTERN
const CONSTRUCTION_TEMPLATE_PATTERN = '/{{(template)(.*?)}}/si' |
Construction template
regular expression
Definition at line 36 of file Template.php.
◆ LOOP_PATTERN
const LOOP_PATTERN = '/{{for(?P<loopItem>.*? )(in)(?P<loopData>.*?)}}(?P<loopBody>.*?){{\/for}}/si' |
Construction for
regular expression
Definition at line 41 of file Template.php.
The documentation for this class was generated from the following file: