Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Smarty PHP插入函数_Php_Smarty - Fatal编程技术网

Smarty PHP插入函数

Smarty PHP插入函数,php,smarty,Php,Smarty,我想在主模板中包含一个子模板。这个子模板应该由php函数呈现(我需要访问数据库)。我在指南中看到,{insert}标记是我应该寻找的,因为include_php已被弃用 现在,我在默认插件目录(/templates/plugins)中有以下文件: 请注意,如果不使用subtemplate/insert(从admin.php获取数据并在admin.tpl中呈现),它就可以工作 “提前感谢”如果您希望包含其他模板使用,则需要结合插件或函数调用 编辑:还要确保包含从模板目录开始的包含模板的完整路径 &

我想在主模板中包含一个子模板。这个子模板应该由php函数呈现(我需要访问数据库)。我在指南中看到,{insert}标记是我应该寻找的,因为include_php已被弃用

现在,我在默认插件目录(/templates/plugins)中有以下文件:

请注意,如果不使用subtemplate/insert(从admin.php获取数据并在admin.tpl中呈现),它就可以工作

“提前感谢”

如果您希望包含其他模板使用,则需要结合插件或函数调用

编辑:还要确保包含从模板目录开始的包含模板的完整路径

<?php

    // /templates/plugins/insert.admin_items.php

    require_once('lib/smarty/Smarty.class.php');

    function smarty_insert_admin_items($params, &$smarty)
    {
        /* fetch items */

       // render page
       $smarty = new Smarty();
       $smarty->assign('items', $sorted_items);
       return $smarty->fetch('admin_items.tpl');    
    }
 ?>
<!-- /templates/admin_items.tpl -->
<div>
  {foreach $items as $i}
    <div>{$i.title}</div>
  {/foreach}
</div>
<!-- /templates/admin.tpl -->
<html>
    <body>
       {insert name="admin_items"}
   </body>
</html>
// /admin.php
<?php
    require_once('lib/smarty/Smarty.class.php');

    $smarty = new Smarty();
    $smarty->display('admin.tpl');
?>
Fatal error: Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template "./templates/admin.tpl" on line 10 "{insert name=&quot;admin_items&quot;}" {insert} no function or plugin found for 'admin_items'' in /Applications/MAMP/htdocs/bo/lib/smarty/sysplugins/smarty_internal_templatecompilerbase.php:431 Stack trace: #0 /Applications/MAMP/htdocs/bo/lib/smarty/sysplugins/smarty_internal_compile_insert.php(92): Smarty_Internal_TemplateCompilerBase->trigger_template_error('{insert} no fun...', 10) #1 /Applications/MAMP/htdocs/bo/lib/smarty/sysplugins/smarty_internal_templatecompilerbase.php(284): Smarty_Internal_Compile_Insert->compile(Array, Object(Smarty_Internal_SmartyTemplateCompiler), Array, NULL, NULL) #2 /Applications/MAMP/htdocs/bo/lib/smarty/sysplugins/smarty_internal_templatecompilerbase.php(123): Smarty_Internal_TemplateCompilerBase->callTagCompiler('insert', Array, Array) #3 /Applications/MAMP/htdocs/bo/lib/smarty/sysplugins/smarty_internal_templateparser.php(2319): Smarty_Internal_TemplateC in /Applications/MAMP/htdocs/bo/lib/smarty/sysplugins/smarty_internal_templatecompilerbase.php on line 431