smarty手记2

简介:
section.php
InBlock.gif<?php 
InBlock.gifrequire_once  "../smarty/Smarty.class.php"
InBlock.gif$smarty= new Smarty(); 
InBlock.gif$smarty->template_dir= "../php/tmps"
InBlock.gif$smarty->compile_dir= "../php/tmps_c"
InBlock.gif$smarty->left_delimiter= "<{"
InBlock.gif$smarty->right_delimiter= "}>"
InBlock.gif 
InBlock.gif$colors=array( "红", "橙", "黄", "绿", "蓝", "靛", "紫"); 
InBlock.gif$smarty->assign( "mycolors",$colors); 
InBlock.gif$smarty->display( "array.tpl"); 
InBlock.gif?>
 
模板文件array.tpl:
 
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > 
< html  xmlns ="http://www.w3.org/1999/xhtml" > 
< head > 
< meta  http-equiv ="Content-Type"  content ="text/html; charset=gbk"  /> 
< title >Smarty--section函数使用 </title> 
</head> 

< body > 
显示数组: < {section name=colorindex loop=$mycolors} > < {$mycolors[colorindex]} > < {/section} > 
</body> 
</html>
 
 
结果:
 
显示数组:红橙黄绿蓝靛紫
 
 




本文转自 xcf007 51CTO博客,原文链接:http://blog.51cto.com/xcf007/111413,如需转载请自行联系原作者


相关文章
|
9月前
|
PHP
php模版引擎smarty出现Undefined index的解决方案
php模版引擎smarty出现Undefined index的解决方案
65 0
|
Web App开发 PHP 索引
smarty、smarty格式化、smarty整数、smarty float、smarty各种转换方式、smarty日期转换等等
smarty code: {config_load file='config.conf'} Smarty学习 {capture name=banner}{*注释掉中间显示内容*} {include file="banner.
1235 0
|
PHP 索引
smarty手册-smarty中foreach循环语句详解
原文地址:smarty手册-smarty中foreach循环语句详解作者:谭博 {foreach}循环也有自身属性的变量,可以通过{$smarty.foreach.name.property}访问,其中"name"是name属性。
1185 0
|
PHP 前端开发 网络架构
|
编解码 JavaScript 前端开发
|
PHP 搜索推荐 数据库

热门文章

最新文章