Why can't Smarty load this block tag plugin
Here is my directory structure:
./smartytest.php
./smarty31/* (libs, etc.) ./plugins/block.sayhi.phpThe 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() . '/plu开发者_Python百科gins';
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?
$smarty->plugins_dir[] = getcwd() . '/plugins';
Should be:
$existing = $smarty->getPluginsDir();
$existing[] = getcwd() . '/plugins';
$smarty->setPluginsDir($existing);
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.
精彩评论