php smarty section使用

文件:section.tpl

<html>
<head>
<title></title>
</head>
<body>

{section name=color loop=$colors}

{*这里是非关联数组,只是普通数组,这里的形式为:下标=>值 *}

{$smarty.section.color.index} => {$colors[color]}<br>

{/section}

</body>
</html>

文件:section.php

<?php
    require("Smarty.class.php");
    $smarty = new Smarty();
    $smarty -> template_dir = "./templates"; //模板存放目录 
    $smarty -> compile_dir = "./templates_c"; //编译目录 
    $smarty -> cache_dir = "./cache"; //缓存目录
    $smarty -> config_dir = "./configs"; //缓存目录
    
    $colors = array('红','黄','蓝');
    $smarty -> assign('colors',$colors);
    
    $smarty -> display('section.tpl');

?>
原文地址:https://www.cnblogs.com/wuyou/p/3388867.html