开发者

Smarty output to PHP Constant is it possible?

开发者 https://www.devze.com 2023-03-09 20:26 出处:网络
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

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

精彩评论

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

关注公众号