喜悦国际村 » PHP高级编程 » [smarty],关于include的文件,文件路径是动态的

页: [1]
顺顺利利2007-3-2 09:06 AM
[smarty],关于include的文件,文件路径是动态的

{{include file="tpl/default/main_top.htm" title=foo}}

我有两个量,分别是
$tpl_dir='tpl/';
$htm_dir='default/';

我想把这两个变量套入到include里面,怎么套呢?

{{include file="tpl/default/main_top.htm" title=foo}}

用PHP的语法来表达我的意思吧

<?
include( $tpl_dir.$tpl_dir.'main_top.htm' );
?>

可是换成模板后,怎么处理呢?

{{include file="tpl/default/main_top.htm" title=foo}}

我要把模板路径 tpl/default 换成是变量 $tpl_dir和$htm_dir

安逸是魔鬼2007-3-2 04:26 PM
没啥区别
{include file=$tpl_name}

顺顺利利2007-3-3 01:32 AM
我的模板文件里面要包含进多个文件,讲会有多个include

如果每个include里面都固定用$tpl_name来做,我就要定义多个模板变量
{include file=$tpl_name}

我需要路径名是变量,而包含进来的文件名不是变量

如何在include内连接变量与字符 ,不知道呀

顺顺利利2007-3-3 01:33 AM
试过
{{include file="$cfg.tpl_dir/main_top.htm" title=foo}}

不成功

pro-m642007-3-5 02:25 AM
官官??

目录树是怎样的?

sunceenjoy2007-3-5 04:25 AM
smarty 里面也有个eval 不知道行不。

顺顺利利2007-3-6 01:32 AM
[quote]原帖由 [i]pro-m64[/i] 于 2007-3-5 10:25 AM 发表
官官??

目录树是怎样的? [/quote]
我拷,谁呀?
目录数我是用Xtree

顺顺利利2007-3-6 02:12 AM
说到底这个问题还是在
如何在{{}}里连接两个模板字符型变量?
的点子上~

angeljyt2007-3-13 05:49 AM
[php]
<?php
$smarty   = new Smarty();
$html_dir ="default";
$tpl_dir    ="tpl";
$smarty->assign("html_dir",$html_dir);
$smarty->assign("tpl_dir",$tpl_dir);
$smarty->display("test.tpl");
?>

test.tpl
{include file=$tpl_dir."/".$html_dir."/main_top.htm" title=foo}

[/php]


查看完整版本: [smarty],关于include的文件,文件路径是动态的


Powered by Discuz! Archiver 6.1.0  © 2001-2006 Comsenz Inc.
Processed in 0.007033 second(s), 2 queries