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

解决方案 »

  1.   

    模板中可以直接调用php的内置函数 至于自定义函数 没有试过  
    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基础   
      

  2.   

    $smarty->register_function("func", "func");
    动态注册模板函数插件,前两个参数是模板函数名称和执行函数名称。
      

  3.   

    可以实现的 我在xoops里面这样写过, 但是xoops的底层代码我也没看, 也不知道他怎么处理的, 你可以看一下!
      

  4.   

    这个还不够基础吗?
     什么是Smarty基础啊  有教程吗?
       难道说这个Smarty手册 是比较高端的?
      

  5.   

    1.在index,php页面$smarty->register_function("authcode","authcode");  //第一个参数为html页面使用的名称,第二个参数为真实的函数名称;function authcode($a,$b)//写个简单的函数{   return $a*$b;}----------------------------------------------------------------------------------------------------------------------------------index.htm<{authcode(3,5)}> //结果为15,注意authcode是没有"$"符号的;
      

  6.   

    {func("123")}
    -------------------
    $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
      

  7.   

    从结果上看 Smarty  是把func 当做了一个标签来看  。。  我想一定有什么语法 。 但是手册上没有写啊。。
      

  8.   

    以下代码测试通过b.tpl
    {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