section.php
<?php
require_once "../smarty/Smarty.class.php";
$smarty= new Smarty();
$smarty->template_dir= "../php/tmps";
$smarty->compile_dir= "../php/tmps_c";
$smarty->left_delimiter= "<{";
$smarty->right_delimiter= "}>";
$colors=array( "红", "橙", "黄", "绿", "蓝", "靛", "紫");
$smarty->assign( "mycolors",$colors);
$smarty->display( "array.tpl");
?>
require_once "../smarty/Smarty.class.php";
$smarty= new Smarty();
$smarty->template_dir= "../php/tmps";
$smarty->compile_dir= "../php/tmps_c";
$smarty->left_delimiter= "<{";
$smarty->right_delimiter= "}>";
$colors=array( "红", "橙", "黄", "绿", "蓝", "靛", "紫");
$smarty->assign( "mycolors",$colors);
$smarty->display( "array.tpl");
?>
模板文件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>
< 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,如需转载请自行联系原作者