How to make a reference constant in a ecshop template an implementation _php tutorial

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

  • 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.