Chcel by som zahrnúť do hlavnej podtabuľkyšablóna. Táto podplot by mala byť poskytnutá funkciou php (potrebujem prístup k db). V sprievodcovi som videl, že značka {insert} je to, čo by som mal hľadať, pretože include_php je zastarané.
Teraz mám nasledujúci súbor v tom, čo by mal byť predvolený adresár doplnkov (/ templates / plugins):
<?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");
}
?>
Podstavec, ktorý sa má zahrnúť:
<!-- /templates/admin_items.tpl -->
<div>
{foreach $items as $i}
<div>{$i.title}</div>
{/foreach}
</div>
Toto je hlavná šablóna
<!-- /templates/admin.tpl -->
<html>
<body>
{insert name="admin_items"}
</body>
</html>
A ako tomu hovorím
// /admin.php
<?php
require_once("lib/smarty/Smarty.class.php");
$smarty = new Smarty();
$smarty->display("admin.tpl");
?>
Toto mi dáva nasledujúcu chybu:
Fatal error: Uncaught exception "SmartyCompilerException" with message "Syntax Error in template "./templates/admin.tpl" on line 10 "{insert name="admin_items"}" {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
Všimnite si, že bez použitia veci subtemplate / insert (načítanie údajov z admin.php a ich vykreslenie v admin.tpl) to funguje.
Vopred ďakujem
odpovede:
0 pre odpoveď č. 1{Insert} Ak chcete zahrnúť použitie inej šablóny, musíte ju zavolať spolu s doplnkom alebo funkciou {Zahŕňajú}
EDIT: Nezabudnite tiež zahrnúť úplnú cestu k vami zahrnutej šablóne, ktorá začína v adresári šablón.