PHP smarty 是如何实现模板嵌套的?

dreamfly_whj 2005-09-29 09:34:15
PHP smarty 是如何实现模板嵌套的?

没怎么用过smarty,不是很熟悉samrty模板嵌套的嵌套方式。

最好有个简单的代码实例。

谢谢!
...全文
295 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
phpgene 2005-10-16
  • 打赏
  • 举报
回复
smarty 实现嵌套了吗? 奇怪
wiwiboy 2005-10-13
  • 打赏
  • 举报
回复
sqlite_list.htm[子模版]
sqlite.htm[主模版]
$tpl->assign("major",$major);
$vard = $tpl->fetch("sqlite_list.htm");
$tpl->assign("major",$vard);
$tpl->display("sqlite.htm");
就OK!
helloyou0 2005-10-13
  • 打赏
  • 举报
回复
不过不知道你需要什么效果,smarty里可能有更方便的方法
helloyou0 2005-10-13
  • 打赏
  • 举报
回复
一样在手册里:
http://smarty.php.net/manual/en/api.fetch.php
dreamfly_whj 2005-10-13
  • 打赏
  • 举报
回复
类似PHP lib的用法

把分析后的模板代码赋给一个{$handle}

你们说的好象不是我想要的
  • 打赏
  • 举报
回复
hsboy(PHP it!) 正解!
duzq 2005-10-08
  • 打赏
  • 举报
回复
index.php
$smarty->display( index.tpl);

index.tpl
在tpl里是html语言写的你想写的东东
netstu 2005-10-05
  • 打赏
  • 举报
回复
二楼的搞错了吧?fetch是啥玩意,和嵌套有关吗?
hsboy 2005-10-05
  • 打赏
  • 举报
回复
load_nav.php
-------------

<?php

// load in variables from a mysql db and assign them to the template
require_once("MySQL.class.php");
$sql = new MySQL;
$sql->query("select * from site_nav_sections order by name",SQL_ALL);
$this->assign('sections',$sql->record);

?>


index.tpl
---------

{* absolute path, or relative to $trusted_dir *}
{include_php file="/path/to/load_nav.php"}

{foreach item="curr_section" from=$sections}
<a href="{$curr_section.url}">{$curr_section.name}</a><br>
{/foreach}
hsboy 2005-10-05
  • 打赏
  • 举报
回复
{include file="header.tpl"}

{* body of template goes here *}

{include file="footer.tpl"}
uuq 2005-10-03
  • 打赏
  • 举报
回复
fetch()
helloyou0 2005-10-03
  • 打赏
  • 举报
回复

为什么你们不喜欢查官方手册,例子又多又典型

http://smarty.php.net/manual/en/language.function.section.php

21,891

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧