开发者

Why can't Smarty load this block tag plugin

开发者 https://www.devze.com 2023-03-25 02:04 出处:网络
Here is my directory structure: ./smartytest.php ./smarty31/* (libs, etc.) ./plugins/block.sayhi.php The PHP code that initializes smarty is:

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() . '/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.

0

精彩评论

暂无评论...
验证码 换一张
取 消