1

I'm usinh a Prestashop 1.5.4.1, and I would like to call a module in other module (precisely I need to use slider module just above the home featured products). I tried to call it via

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

but always I get only blank page without any code. I also tried with different ways of directory statement, but always the result was the same. Is there any possibility to include new module in correct way?

Matteo Enna
  • 1,285
  • 1
  • 15
  • 36
kacper
  • 370
  • 2
  • 6
  • 13

4 Answers4

5

For this to work, your directory structure should be (Using PrestaShop 1.6):

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

Absolute way:

From your main module file:

protected function displayFooBarTemplate()
{
    global $smarty;

    ...

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

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

then in your tpl file (displayFooBarTemplate.tpl):

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

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

Relative way (my favorite):

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

{include './inc/modal/bar.tpl'}
  • {include 'inc/foo.tpl'} did not work but {include './inc/foo.tpl'} did!! – user109764 Jun 10 '16 at 14:21
  • What am I doint worng... {include file="$tpl_dir./modules/blockcategories/blockcategories.tpl"} -> in product.tpl . Why is the .tpl file for categories not loading ? Any Idea ? – Blue Feb 14 '17 at 17:06
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.

0

Proper way to include a smarty tag includes using the curl brackets.

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

Note that the directory in the include statement should be relative to the templates directory.

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

Panama Jack
  • 24,158
  • 10
  • 63
  • 95
0

In your php code declare a variable like this :

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

Then in your smarty template :

{include file=$tpl_path/my_file.tpl}

Compatible with Prestashop 1.4 and 1.5.

AlexDeb
  • 157
  • 5