Note: Make the ecshop template can reference Constants

Source: Internet
Author: User

Introduction: This is a note: This is a detailed page that enables ecshop templates to reference constants. It introduces PHP, related knowledge, skills, experience, and some PHP source code.

Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 337306 'rolling = 'no'>

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 smarty, and has many features.

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 rows to the make_var () function.Code

1 function make_var ($ Val)
2 {
3 if (strrpos ($ Val, '.') = false)
4 {
5 If (isset ($ this-> _ var [$ Val]) & isset ($ this-> _ patchstack [$ Val])
6 {
7 $ val = $ this-> _ patchstack [$ Val];
8}
9 $ P = '$ this-> _ var [\ ''. $ Val.' \ ']';
10}
11 else
12 {
13 $ T = explode ('.', $ Val );
14 $ _ var_name = array_shift ($ t );
15 if (isset ($ this-> _ var [$ _ var_name]) & isset ($ this-> _ patchstack [$ _ var_name])
16 {
17 $ _ var_name = $ this-> _ patchstack [$ _ var_name];
18}
19 if ($ _ var_name = 'smarty ')
20 {
21 if ($ t [0] = 'const '){
22 return strtoupper ($ t [1]);
23
}
24 $ P = $ this-> _ compile_smarty_ref ($ t );
25}
26 else
27 {
28 $ P = '$ this-> _ var [\ ''. $ _ var_name.' \ ']';
29}
30 foreach ($ T as $ Val)
31 {
32 $ P. = '[\ ''. $ Val.' \ ']';
33}
34}
35
36 return $ P;
37}

Lines 21-23 are newly added, which allows you to reference constants defined in PHP through {$ smarty. Const. Constant} in the template file.

Love J2EE follow Java Michael Jackson video station JSON online tools

Http://biancheng.dnbcw.info/php/337306.html pageno: 9.

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.