It is said that the template class of ecshop is the modified smarty, but I personally feel that the modification is not completely rewritten. It is the same as the template tag on the smarty, while caressing many functions of Ecshop.
For example, $ smarty. const. 'constant 'cannot be used.
In fact, the template engine is not complex in principle. it just replaces some template labels with functions, variables, and syntax structures in php.
To add the reference constant function to the ecshop template this time, you only need to add two lines of code to the make_var () function.
The 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;
}
Lines 21-23 are newly added, which allows you to reference constants defined in php through {$ smarty. const. constant} in the template file.
The code is as follows:
21 if ($ t [0] = 'const '){
22 return strtoupper ($ t [1]);
23}