教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 smarty 模板if else使用实例与入门教程

smarty 模板if else使用实例与入门教程

发布时间:2016-10-27   编辑:jiaochengji.com
教程集为您提供smarty 模板if else使用实例与入门教程等资源,欢迎您收藏本站,我们将为您提供最新的smarty 模板if else使用实例与入门教程资源
标签是给Smarty的指令符,以模板定界符包住。这些指令符可以是变量,以$符号代表函数、逻辑 或 流程控制 语法。Smarty 允许 PHP 程式设计师以Smarty 标签去定义可存取的函数

smarty 模板if else使用实例与入门教程
smarty 主要功能是完成美工与程序分离,并且使用的缓存技术,减轻服务器的负载,
smarty 以在文件中放置特殊的“Smarty标签”来产生网页内容。这些标签会被处理并替换成其他的内容。

 

*/

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.jiaochengji.com'
$tpl->assign('dataList', $array);
$tpl->display('a.tpl');

/*
a.tpl
<!--{if $dataList =='www.jiaochengji.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}

本文章原创于www.jiaochengji.com转载注明出处

您可能感兴趣的文章:
smarty 模板if else使用实例与入门教程
php smarty 基础
有关smarty的基本设置
smarty结合xajax检测用户名
smarty获得当前url示例代码
smarty结合xajax检测用户名简单实例
php模版生成html的小例子
PHP模板引擎Smarty缓存使用
如何将smarty安装到MVC架构中(代码示例)
有关smarty缓存的应用

[关闭]
~ ~