b.tpl
{func var="xxx"}---------------------------
A.phpfunction func ($a){
echo "hi ".$a;
}
$smarty = new Smarty;
$smarty->display('tt.tpl');-----------------------------执行 a.php 让B.tpl 输出 hi xxx
{func var="xxx"}---------------------------
A.phpfunction func ($a){
echo "hi ".$a;
}
$smarty = new Smarty;
$smarty->display('tt.tpl');-----------------------------执行 a.php 让B.tpl 输出 hi xxx
lz 就是想在模板中打印func 的结果
那就在A.php中直接调用func函数
b.tpl
{$test}---------------------------
A.phpfunction func ($a){
echo "hi ".$a;
}
$smarty = new Smarty;
$test = func("xxxx");
$smarty -> assign('test', $test);
$smarty->display('tt.tpl');建议lz看看smarty基础
动态注册模板函数插件,前两个参数是模板函数名称和执行函数名称。
什么是Smarty基础啊 有教程吗?
难道说这个Smarty手册 是比较高端的?
-------------------
$smarty->register_function("func","func");
$smarty->display('tt.tpl');function func ($a){
return "aaaaaaaa.........".$a;
}---------------------------
错误提示
Fatal error: Smarty error: [in tt.tpl line 6]: syntax error: unrecognized tag: func("123") (Smarty_Compiler.class.php, line 446) in D:\wamp\www\smarty_temp\smarty\libs\Smarty.class.php on line 1113
{func var="xxx" num="123"}---------------------------
A.php<?php
require 'Smarty/Smarty.class.php';
function func($params){
return "hi ".$params['var'].",".$params['num'];
}
$smarty = new Smarty;
$smarty->register_function("func", "func");
$smarty->display(dirname(__FILE__).'\\b.tpl');
?>
-----------------------------
输出:hi xxx,123