0

カスタム smarty 関数を作成したい。関数を作成しました

 function smarty_function_vbchecker($params, &$smarty)
{
    $length = strlen($params['vbstring']);
    $output = "Your sentence is too long. Shorten It!";
    if($length < 50)
        $output = "Your sentence is just right!";

    return $output;
}
?>

ファイルを smarty/libs/plugins ディレクトリに保存しました。その後、テンプレートファイルtestfunction.tplを作成しました

{vbchecker vbstring='See, it is very easy to write a function.'}

ファイルを smarty/templates ディレクトリに保存しました

出力を確認するために呼び出しているファイル testfun.php も作成しました。

<?php
require 'Smarty/libs/Smarty.class.php';

$smarty = new Smarty;


    $smarty->display('tesfunction.tpl');
    ?>

しかし、testfun.php を実行するとエラーが表示されます:

Fatal error: Uncaught exception 'SmartyException' with message 'Unable to load template file 'tesfunction.tpl'' in D:\xampp\htdocs\smarty\smarty\libs\sysplugins\smarty_internal_templatebase.php:127 Stack trace: #0 D:\xampp\htdocs\smarty\smarty\libs\sysplugins\smarty_internal_templatebase.php(374): Smarty_Internal_TemplateBase->fetch('tesfunction.tpl', NULL, NULL, NULL, true) #1 D:\xampp\htdocs\smarty\testfun.php(7): Smarty_Internal_TemplateBase->display('tesfunction.tpl') #2 {main} thrown in D:\xampp\htdocs\smarty\smarty\libs\sysplugins\smarty_internal_templatebase.php on line 127

これの原因は何ですか。出力を表示するにはどうすればよいですか。

Fatal error: Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template ".\templates\testfunction.tpl" on line 9 "{vbchecker vbstring='See, it is very easy to write a function.'}" unknown tag "vbchecker"' in D:\xampp\htdocs\smarty\smarty\libs\sysplugins\smarty_internal_templatecompilerbase.php:656 Stack trace: #0 D:\xampp\htdocs\smarty\smarty\libs\sysplugins\smarty_internal_templatecompilerbase.php(441): Smarty_Internal_TemplateCompilerBase->trigger_template_error('unknown tag "vb...', 9) #1 D:\xampp\htdocs\smarty\smarty\libs\sysplugins\smarty_internal_templateparser.php(2393): Smarty_Internal_TemplateCompilerBase->compileTag('vbchecker', Array) #2 D:\xampp\htdocs\smarty\smarty\libs\sysplugins\smarty_internal_templateparser.php(3096): Smarty_Internal_Templateparser->yy_r36() #3 D:\xampp\htdocs\smarty\smarty\libs\sysplugins\smarty_internal_templateparser.php(3196): Smarty_Internal_Templateparser->yy_reduce(36) #4 D:\xampp\htdocs\smarty\smarty\libs\sysplugins\smarty_internal_smartytemplatecompiler. in D:\xampp\htdocs\smarty\smarty\libs\sysplugins\smarty_internal_templatecompilerbase.php on line 656
4

1 に答える 1