您当前的位置: 首页 > 学无止境 > 网站建设 网站首页网站建设
smarty中不同变量、数组、对象、配置文件变量等在模版中的使用
发布时间:2016-03-09 22:50:46编辑:雪饮阅读()
一维数组的遍历:
{foreach from=$content item=temp}
{$temp}
{/foreach}
二维数组的遍历:
{foreach from=$content item=temp}
{foreach from=$temp item=xtemp}
{$xtemp}
{/foreach}
{/foreach}
面向对象式访问属性:
{$content->a->name}
content对象的a属性也是一个对象
模版中引入配置文件并使用:
<title>模板页</title>
{config_load file='../templates/my.conf'}
</head>
<body>
{#title#}
<br/>
{#content#}
</body>
配置文件内容如:
title="我的第一个谢谢"
content="内容"
配置文件在templates目录下与模版同一个目录,当然可以随意灵活变通的
模版中使用保留变量可直接获取请求参数值,get或post:
{$smarty.get.username}
遍历输出数组(键与值):
{foreach from=$content item=temp key=k}
{$k}={$temp}
{/foreach}
关键字词:smarty,模版,变量
上一篇:smarty中变量的分配