php模板引擎smarty案例下载,利用PHP模板引擎smarty

利用PHP模板引擎smarty

#$sections参数可以不写,默认值为null,$smarty->configLoad('test.conf')则只使用全局的键值,而不能使用标签下的键值

#在模版下通过{config_load file="test.conf" section="china" scope="global"}语句调用配置文件

#section属性可以不写,默认是null,scope属性必须写{config_load file="test.conf" scope="global"}

#section属性可赋三种值

#local 只有当前模版可以使用该配置文件

#parent 只有当前模版引入该配置文件语句后包含的模版中,或在php源文件中smarty对象调用该配置文件后调用的模版中可以使用该配置文件中的键值

#global 测试效果和parent相同

#在模版中通过{#language#}来使用键值,也可以通过{$smarty.config.language}来访问配置文件键值

#PHP源文件中可以使用$smarty->getConfigVars('language')或$smarty->getConfigVariable('language')来获取键值,$smarty->getConfigVars('language')获取的还可能是数组

*/

/*

tpl文件中常用函数

tpl文件:

{capture name="testCapture"}

{include file="f1.tpl"}

{/capture}

{if true}

{$smarty.capture.testCapture}

{/if}

{if $name == "wang"}

Welcome wang.

{elseif $name == "zhang"}

Welcome zhang.

{else}

Welcome, whatever you are.

{/if}

{*操作符可以是 ==,>= 等也可以是 eq,ne等*}

{for $x=0; $x

{$x}

{/for}

{*for循环,类似PHP代码*}

{$x=0}

{while $x

{$x++}

{/while}

{*While循环,也类似PHP代码。*}

{foreach name="testForeach" from=$testArr key=arId item=arVal}

{$arId}对应的值为:{$arVal}

{$smarty.foreach.testForeach.index}

{$smarty.foreach.testForeach.iteration}

{$smarty.foreach.testForeach.first}

{$smarty.foreach.testForeach.last}

{$smarty.foreach.testForeach.total}

{foreachelse}

$testArr is null

{/foreach}

{*也可以如下两种类PHP格式*}

{foreach $testArr as $n}

{$n}

{/foreach}

{foreach $testArr as $key=>$n}

{$key}

{/foreach}

{$sectionArr = [0=>"a",4=>"b","c","d","e",6,7,8,9,10,11,12,13,14,15,16]}

{section name="testSection" loop=$sectionArr start=0 step=4 max=6 show=true}

{$smarty.section.testSection.index}-

{$sectionArr[testSection]}-

{$smarty.section.testSection.iteration}-

{sectionelse}

$sectionArr is null

{/section}

*/

/*

tpl模板文件:

{literal}

script type="text/javascript"

function a(){

alert("this is script");

}

a();

/script

【利用PHP模板引擎smarty】相关文章:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值