smarty用php标签怎么输出变量
index.php
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
$smarty = new Smarty;
$smarty->allow_php_tag=true;
$smarty->assign("a", "aaaaaaaaaaaaaa");
$smarty->display('index.tpl');
//php文件中这样写
global $var;//申明全局变量
...
$var = 'Hi Smarty';//赋值,无需再使用smarty的assign方法
//模板中这样获取
echo $GLOBALS['var'];
<br><font color="#e78608">------解决方案--------------------</font><br>为什么要用php标签,{变量}就可以,循环可以用foreach section等,够你用的。
<br><font color="#e78608">------解决方案--------------------</font><br>直接<br>{$a} 就可以了,如果你想对数据再进行处理可以看看手册
<br><font color="#e78608">------解决方案--------------------</font><br>可以,但是你必须定义定界符,<br>$smarty->left_delimiter="{php}";//指定左定界符<br>$smarty->right_delimiter="/{php}>";//指定左定界符<br>中间的echo就不要了,直接是{php}$a{/php}<br><br><font color="#e78608">------解决方案--------------------</font><br>[php]<br> echo "这是php代码";<br>[/php]<br><br>有得版本是可以直接在模板里写php代码的 <div class="clear"></div>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号