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...
精彩评论