1

我正在使用 Prestashop 1.5.4.1,我想在其他模块中调用一个模块(确切地说,我需要在家庭特色产品上方使用滑块模块)。我试图通过调用它

包括文件='../directory/module.tpl'

但总是我只得到没有任何代码的空白页。我也尝试了不同的目录声明方式,但结果总是一样的。是否有可能以正确的方式包含新模块?

4

4 回答 4

5

为此,您的目录结构应该是(使用 PrestaShop 1.6):

-- mymodule.php
-- views
---- templates
------ hook
------ displayFooBarTemplate.tpl
-------- inc
---------- foo.tpl
---------- bar.tpl

绝对方式:

从您的主模块文件中:

protected function displayFooBarTemplate()
{
    global $smarty;

    ...

    $smarty->assign('module_templates', dirname(__FILE__).'/views/templates/');

    return $this->display(__FILE__, 'displayFooBarTemplate.tpl');
}

然后在您的 tpl 文件(displayFooBarTemplate.tpl)中:

{include file="{$module_templates}hook/inc/modal/foo.tpl"}

{include file="{$module_templates}hook/inc/modal/bar.tpl"}

相对方式(我最喜欢的):

{include './inc/foo.tpl'}

{include './inc/modal/bar.tpl'}
于 2015-01-05T19:48:42.950 回答
1

What worked for me in Prestashop 1.6 is

{include file="$tpl_dir/modules/blocknewsletter/blocknewsletter.tpl"}

I put this in the footer.tpl file and correctly displayed the text box for subscribing to the newsletter. I suppose it works for all other modules, too.

于 2014-05-22T09:43:41.267 回答
0

在你的 php 代码中声明一个像这样的变量:

$this->path_to_tpl_folder = str_replace('\\', '/', _PS_MODULE_DIR_) . 'mon_module/tpl';
$this->context->smarty->assign('tpl_path', $this->path_to_tpl_folder)

然后在您的 smarty 模板中:

{include file=$tpl_path/my_file.tpl}

与 Prestashop 1.4 和 1.5 兼容。

于 2014-01-19T13:12:52.847 回答
0

包含 smarty 标签的正确方法包括使用大括号。

{include file='directory/module.tpl'}

请注意,include 语句中的目录应该是相对于模板目录的。

http://www.smarty.net/docsv2/en/language.function.include.tpl

于 2014-01-13T18:51:43.553 回答