How to make constants referenceable in ecshop templates_PHP tutorial

WBOY
Release: 2016-07-21 15:29:36
Original
871 people have browsed it

For example, $smarty.const.'constant' cannot be used.
In fact, the template engine is not complicated in principle. It just replaces some template tags with functions, variables, and grammatical structures in PHP.
To add the function of reference constants to the ecshop template this time, just add two lines of code to the function make_var()

Copy the code 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;
}

where 21-23 The line is newly added, which allows you to reference the constants defined in PHP through {$smarty.const.const} in the template file
Copy code The code is as follows:

21 if($t[0] == 'const'){
22 return strtoupper($t[1]);
23 }

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323423.htmlTechArticleFor example, $smarty.const.'constant', this cannot be used. In fact, the template engine is not complicated in principle. It just replaces some template tags with functions, variables, and grammatical structures in PHP. This...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template