How to enable the ecshop template to reference constants

Source: Internet
Author: User
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}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.