简体   繁体   English

Smarty-包含带有MySQL代码的模板文件

[英]Smarty - include template file with MySQL code

Am using WHMCS, and trying to create a separate file for my header menu. 我正在使用WHMCS,并尝试为我的标题菜单创建一个单独的文件。 The header menu is a multidimensional array, and I wanted it to be kept separate for my own sanity sake. 标题菜单是一个多维数组,出于我自己的理智,我希望将其分开。

I created a .php page with the MySQL code as such: 我用MySQL代码创建了一个.php页面,如下所示:

<?php ... 
# To assign variables to the template system use the following syntax.
# These can then be referenced using {$variablename} in the template.
$smartyvalues["variablename"] = $value; 

$list = array();
$result = full_query("SELECT id,title,slug,parent FROM `pages` WHERE title!='404' AND slug!='404'");

...
$smartyvalues["header"] = $list;
# Define the template filename to be used without the .tpl extension
$templatefile = "headermenu"; 
outputClientArea($templatefile);
?>

The headermenu.tpl shows the menu as it should, but when I try to include the file elsewhere, the menu is blank. headermenu.tpl会按原样显示菜单,但是当我尝试将文件包含在其他位置时,菜单为空白。 I add some static content, and that shows. 我添加一些静态内容,然后显示出来。 I tried using both {include} and {include_php} to no avail. 我尝试同时使用{include}和{include_php}无济于事。 Any idea how I can show my MySQL result without directly putting it into the file I need it in? 知道如何在不直接将MySQL结果放入需要的文件的情况下显示MySQL结果吗?

I could not figure out a way to include the file through .tpl, so I created a .php and included it with {include_php}. 我无法找到通过.tpl包含文件的方法,因此我创建了.php并将其包含在{include_php}中。 The .php had my MySQL code, and after including the file, I was able to show the MySQL result as needed. .php有我的MySQL代码,并且在包含文件后,我能够根据需要显示MySQL结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM