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 CodeThe code is 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 CodeThe code is as follows:
if ($t [0] = = ' Const ') {
return Strtoupper ($t [1]);
23}
http://www.bkjia.com/PHPjc/323423.html www.bkjia.com true http://www.bkjia.com/PHPjc/323423.html techarticle 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 ...