4

我正在使用 Prestashop 为客户创建店面。Prestashop 使用 Smarty .TPL 文件。我通读了 smarty 文档并搜索了网络,但所有建议都不起作用。

我首先使用常规的 .php 页面创建了一个站点,并且在每个页面上都包含了 header.php。

然后我为 prestashop 创建了一个目录并进行了设置。我编辑了 header.tpl 文件,并且能够在 header.php 代码中进行硬编码。问题是;当我想编辑标题(导航栏、图像、社交媒体)时,我必须在两个不同的地方进行编辑。所以我尝试“包含”我的 header.php 文件。

虽然,当我尝试使用 smarty 的 {include_PHP "file.php"} 和/或 {PHP}include...{PHP} 时,Prestashop 出错并给我一个空白的白页 - 没有给出错误 - (在 chrome 中它给出我是“服务器错误”),直到我取出包含在内。

我尝试将整个 header.tpl 代码替换为 smarty 包含和另一段具有标头钩子的代码,但这些都不起作用。有什么建议么?我只需要一个标题,我只需编辑一次即可进行更改。

使用 Prestashop v 1.4.4.0

编辑:我将 allow_php 从 false 更改为 true。现在它正在尝试添加文件,尽管它说找不到文件。我将它放在 header.tpl 旁边,然后使用:

{php}
            include('navBar.php'); 
       {/php} 
4

2 回答 2

4

回答!

使用 Smarty .TPL 文件时,当您包含某些内容时,您并没有包含您正在处理的文件的路径。您正在包括索引所在的位置。

例子:

我正在研究 header.tpl,它位于:siteroot/ smartyinstall /themes/ themename /header.tpl

当包含查找文件时,它实际上是在 smarty 根文件夹中查找它,因为 header.tpl 被拉入smartyinstall文件夹中的 index.html 页面。

所以,你必须从那里出发。就我而言,我试图包含的标题位于:siteroot/includes/navBar.php

所以,我不得不写 include('../includes/navBar.php');,只上一个目录,而不是四个。

我希望这可以帮助每个有这种问题的人!

于 2011-09-02T00:56:59.247 回答
0

It's considered very bad practice to include php in smarty .tpl files so I would strongly recommend you don't add code this way. One of the main reasons for disabling the {php} tag is to help prevent code injection attacks. eCommerce sites are by their very nature natural targets for exploits.

A better approach would be to override the FrontController class to assign your custom code to a smarty variable - this could then be inserted into the header.tpl without resorting to using a php include().

With the class and controller overrides available in Prestashop 1.4.x there's no real reason you should need to resort to hacks and/or modifications to the core distribution.

Paul

于 2011-09-02T22:34:53.703 回答