为什么Smarty无法加载这个块标签插件
这是我的目录结构:
./smartytest.php
./smarty31/*(库等)
./plugins/block.sayhi.php
初始化 smarty 的 PHP 代码是:
require_once('smarty31/libs/Smarty.class.php');
$smarty = new Smarty();
$smarty->template_dir = getcwd() . '/templates';
$smarty->compile_dir = getcwd() . '/templates_c';
$smarty->plugins_dir[] = getcwd() . '/plugins';
插件的 PHP 代码是:
<?php
function smarty_block_sayhi($params, $content, $smarty, $open) {
if (!$open) {
return 'Hello: ' . $content;
}
}
?>
我得到的错误消息是这样的:
致命错误:未捕获异常“SmartyCompilerException”并带有消息 '模板“/mypath/phptests/templates/page.tpl”中的语法错误 第 11 行“{sayhi}”未知标签“sayhi”'
当插件位于 smarty31/libs/plugins 目录下时,加载正常。此示例代码是否未正确初始化 Smarty?
Here is my directory structure:
./smartytest.php
./smarty31/* (libs, etc.)
./plugins/block.sayhi.php
The PHP code that initializes smarty is:
require_once('smarty31/libs/Smarty.class.php');
$smarty = new Smarty();
$smarty->template_dir = getcwd() . '/templates';
$smarty->compile_dir = getcwd() . '/templates_c';
$smarty->plugins_dir[] = getcwd() . '/plugins';
The PHP code for the plugin is:
<?php
function smarty_block_sayhi($params, $content, $smarty, $open) {
if (!$open) {
return 'Hello: ' . $content;
}
}
?>
The error message I get is this:
Fatal error: Uncaught exception 'SmartyCompilerException' with message
'Syntax Error in template "/mypath/phptests/templates/page.tpl" on
line 11 "{sayhi}" unknown tag "sayhi"'
When the plugin was under the smarty31/libs/plugins directory, it loaded fine. Does this sample code not initialize Smarty correctly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
应该是:
原来我正在看一个 PHP 4 示例; Smarty 3.1 使用 PHP 5 访问修饰符,因此我无法以这种方式更改 plugins_dir 。
Should be:
Turns out I was looking at a PHP 4 example; Smarty 3.1 uses PHP 5 access modifiers so I couldn't change plugins_dir that way.