开发者

Smarty output to PHP Constant is it possible?

I got constant in PHP

This constant is written in Mysql

With Smarty i am doing output to HTML

Is it possible to output Smarty results to php not to HTML

<? {$CONSTANTS_RESULT[LOOP]} ?>
开发者_JAVA百科

?


To access PHP constants in Smarty, you can use {$smarty.const.MY_CONSTANT} which is documented here.


or:

$smarty->registerFilter('pre',array($this,'preFilterConstants'));

// '#' Const in Smarty...
public function preFilterConstants($strInput, $objSmarty) {
  return preg_replace('|(<!--\{[^\}]+)#([A-Za-z0-9_]+)(.+?\}-->)|si','$1\$smarty.const.$2$3',$strInput);
}

and do:

<? <!--{#MY_CONSTANT}--> ?>

if you want to use other delimiter just edit pattern...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜