such as $smarty.const. ' Constant ', this cannot be used.
In fact, the template engine is not complicated in principle, just replace some template tags with PHP functions, variables, grammatical structure.
This time to add a reference constant to the Ecshop template, just add two lines of code in the function Make_var ()
Copy the 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 the rows are new, which allows you to refer to the constants defined in PHP by {$smarty. Const. Constants} in the template file.
Copy the Code code as follows:
if ($t [0] = = ' Const ') {
return Strtoupper ($t [1]);
23}
The above describes the Ecshop template to make the Ecshop template can be referenced constants of the implementation method, including the content of the Ecshop template, I hope that the PHP tutorial interested in a friend helpful.