【问题标题】:Smarty, pages in subdirectoriesSmarty,子目录中的页面
【发布时间】:2011-01-09 20:03:30
【问题描述】:

我试图弄清楚如何使用 php Smarty 模板引擎将页面保存在子目录(类别)中。

例如,如果我的结构是:

index.php
category1/page1.php
category2/page2.php

等等

根 index.php 渲染得很好

使用默认的 smarty 设置:

<?php 
require_once('lib/smtemplate.php');

$data = array(
    'meta_keywords' =>'key1, key2',
    'category' =>'category1'
    );

$tpl = new SMTemplate();
$tpl->render('page', $data);

?>

但是如果我将它复制到子目录中,即使我更改为它也会中断

require_once('../lib/smtemplate.php');

到目前为止我还没有找到解决方案。

感谢您的帮助。 谢谢。

【问题讨论】:

  • 您的模板文件在哪里? SMTemplate 的代码是什么?您是否设置了 Smarty 对象的正确 template_dir 属性?在提问之前,您是否费心阅读文档 [smarty.net/docs/en/variable.template.dir.tpl]?

标签: php smarty template-engine


【解决方案1】:

定义基本路径:

define("BASEPATH", "/var/www/yoursite/");

并像这样包含:

require_once(BASEPATH.'lib/smtemplate.php');

【讨论】:

  • 刚刚尝试过,但没有成功。这是我得到的错误:致命错误:未捕获的异常 'SmartyException' 并在 E:\wamp\www\smarty\lib\smarty\sysplugins\smarty_internal_template.php:163 中显示消息 '无法加载模板文件 'hello.tpl''堆栈跟踪:#0 E:\wamp\www\smarty\lib\smarty\sysplugins\smarty_internal_template.php(541): Smarty_Internal_Template->isExisting(true) #1 E:\wamp\www\smarty\lib\smarty\Smarty .class.php(337): Smarty_Internal_Template->getRenderedTemplate() #2 E:\wamp\www\smarty\lib\smtemplate.php(30): Smarty->fetch('hello.tpl')
  • 或我使用的shell define("BASEPATH", "/var/www/yoursite/");也通过所有配置文件?
  • 你应该。但是找到“hello.tpl”也有麻烦......我认为最好的解决方案是“修复你的路径”:D
  • 我的根 index.php 文件与 hello.tpl 一起渲染得很好,所以我无法相信 Smarty 无法管理子目录中的页面。
  • 如果你设置了从相对路径加载的东西,恐怕你会遇到问题。包含来自不同子目录的内容总是如此,抱歉,但就是这样......例如也适合你的 template_c 目录......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-22
  • 1970-01-01
  • 2015-04-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多