2014-01-13 117 views
0

我使用的是Prestashop 1.5.4.1,我想在其他模块中调用模块(正好我需要在家用特色产品上方使用滑块模块)。我试图通过在.tpl文件中包含其他.tpl Prestashop

包括文件来调用它=“.. /目录/ module.tpl”

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

回答

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) 

然后在您的智者的模板:

{include file=$tpl_path/my_file.tpl} 

与PrestaShop 1.4和1.5兼容。

1

什么的Prestashop 1.6工作对我来说是

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

我把这个在footer.tpl文件,并正确显示文本框中订阅电子报。我想它也适用于所有其他模块。

3

对于这个工作,你的目录结构应该是(使用的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'} 
+0

{包括 'INC/foo.tpl'}没有工作,但{包括 './inc/foo.tpl'}做了! – user109764

+0

我doint worng ... {包含文件=“$ tpl_dir./modules/blockcategories/blockcategories.tpl”} - >在product.tpl中。为什么没有加载类别的.tpl文件?任何想法 ? – Blue