我想创建自定义 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