发新话题
打印

OakWeb--之Smarty的dynamic section

OakWeb--之Smarty的dynamic section

<?php

// This just initializes Smarty with the locations of the
// directories it will use

$full_path =         dirname(__FILE__)."/";

define ("SMARTY_DIR",$full_path."libs/Smarty/");
define ("TEMPLATES_PATH",$full_path . "templates");
define ("TEMPLATES_C_PATH",$full_path . "templates_c");
define ("CONFIGS_PATH",$full_path . "configs");
define ("CACHE_PATH",$full_path . "cache");

require_once SMARTY_DIR."Config_File.class.php";
require_once SMARTY_DIR."Smarty.class.php";

// Initialize a new smarty object
$smarty = new Smarty ();

// Assign some variables in our templates file
$smarty->assign ("title", "Smarty Introduction");
$smarty->assign ("body", "Hello There.");

// Thanks goes out to the authors of Smarty
// Note we are appending here and filling in a dynamic section
$smarty->append ("first", "Monte");
$smarty->append ("last", "Ohrt");

$smarty->append ("first", "Andrei");
$smarty->append ("last", "Zmievski");

// Show the template
$smarty->display ("index.tpl");

?>


index.tpl
examples/smarty/templates/index.tpl

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"        "http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />    <title>{$title}</title></head><body><h1>{$title}</h1><p>{$body}</p><h3>I'd like to thank these people for making this possible:</h3><ul>{* This is a Smarty comment *}{section name="thank" loop=$first}    <li>{$first[thank]} {$last[thank]}</li>{sectionelse}    <li>No names were found.</li>{/section}</ul></body></html>
努力为phpres做贡献
时刻准备着,当机会来临时你就成功了
打好基础,增加社会经验
资深技术工程师是我的梦想
承接各种团体网站外包服务和各种it技术培训
准备申请AJAX版大,希望大家支持~~

TOP

支持一下
爱上PHP,便拥有了更多的动力!

TOP

发新话题