smarty 模板if else使用实例与入门教程
标签是给Smarty的指令符,以模板定界符包住。这些指令符可以是变量,以$符号代表函数、逻辑 或 流程控制 语法。Smarty 允许 PHP 程式设计师以Smarty 标签去定义可存取的函数
smarty 模板if else使用实例与入门教程
smarty 主要功能是完成美工与程序分离,并且使用的缓存技术,减轻服务器的负载,
smarty 以在文件中放置特殊的“Smarty标签”来产生网页内容。这些标签会被处理并替换成其他的内容。
<?php require('smarty/libs/Smarty.class.php教程'); $tpl = new Smarty(); $tpl->template_dir = 'd/' $tpl->compile_dir = 'd/template_c'; $tpl->compile_check = false;//$cfg['debug']; $tpl->debugging = false; $tpl->caching = false; $tpl->cache_lifetime = 3600; $tpl->left_delimiter = '<!--{'; $tpl->right_delimiter = '}-->'; $array = 'www.phprm.com' $tpl->assign('dataList', $array); $tpl->display('a.tpl');
/*
a.tpl
<!--{if $dataList =='www.phprm.com'}-->
<!--{$dataList}-->
<!--{else}-->
echo 'aaa';
<!--{/if}-->
还有另一种方法
{if $name eq 'Fred'}
Welcome Sir.
{elseif $name eq 'Wilma'}
Welcome Ma'am.
{else}
Welcome, whatever you are.
{/if}
{* an example with "or" logic *}
{if $name eq 'Fred' or $name eq 'Wilma'}
...
{/if}
永久链接:http://www.phprm.com/code/b0ee4f9ad9f152c2e009ca21b2e1d9b7.html
转载随意!带上文章地址吧。