比如$smarty.const.'常量',这个就不能用。
其实模板引擎原理上并不复杂,只是把一些模板标签替换为php中的函数,变量,语法结构罢了。
这次要在ecshop模板中加入引用常量的功能,只需在函数make_var()中加入两行代码
复制代码 代码如下:
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行是新加的,这让就可在模板文件中通过 {$smarty.const.常量}来引用php中定义的常量了
复制代码 代码如下:
21 if($t[0] == 'const'){
22 return strtoupper($t[1]);
23 }

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

Dreamweaver CS6
視覺化網頁開發工具

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

SublimeText3漢化版
中文版,非常好用

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。