such as $smarty.const. ' Constants ', this is not available.
In fact, the template engine principle is not complex, just to replace some template tags in php functions, variables, syntax structure.
To add a reference constant to the Ecshop template this time, just add two lines of code to the function Make_var ()
Copy Code code as follows:
function Make_var ($val)
{
if (Strrpos ($val, '. ') = = False)
{
if (Isset ($this->_var[$val]) && isset ($this->_patchstack[$val]))
{
$val = $this->_patchstack[$val];
}
$p = ' $this->_var[\ '. $val. '\']';
}
Else
{
$t = Explode ('. ', $val);
$_var_name = Array_shift ($t);
if (Isset ($this->_var[$_var_name]) && isset ($this->_patchstack[$_var_name]))
{
$_var_name = $this->_patchstack[$_var_name];
}
if ($_var_name = = ' Smarty ')
{
if ($t [0] = = ' Const ') {
return Strtoupper ($t [1]);
}
$p = $this->_compile_smarty_ref ($t);
}
Else
{
$p = ' $this->_var[\ '. $_var_name. '\']';
}
foreach ($t as $val)
{
$p. = ' [\ '. $val. '\']';
}
}
return $p;
}
21-23 of these lines are new, allowing you to refer to the constants defined in PHP by using the {$smarty. Const. Constant} in the template file.
Copy Code code as follows:
if ($t [0] = = ' Const ') {
return Strtoupper ($t [1]);
23}