Jump to content

How to use templates from themes into a module front controller ?


Recommended Posts

Hello,

 

I need to create a custom page for a client on Prestashop, so I am using a module front controller, but I cannot find a way to call a template that I created in the theme, i.e, I created themes/mytheme/templates/custom_template.tpl (which call other templates of the theme) and I want to display this template in the module front controller like this:

public function initContent()
{
   // Exemple taken from the doc for a template belonging to the module
  //$this->setTemplate('modules:cheque/views/templates/front/validation.tpl');

   // What I would like to do
   $this->setTemplate('themes:mytheme/templates/custom_template.tpl');
}

 

Why I don't create a template inside the module folder ? Because I really need to use the template from the theme. Any one has a solution for this ?

 

Thanks a lot

 

Link to comment
Share on other sites

Hi,

Use smarty extend in your module template.

Exemple : in /modules/{my_module}/views/templates/front/module_template.tpl

{extends file='catalog/listing/product-list.tpl'}

{block name='product_list_header'}
   <div class="my-header">....<div>
{/block}     

The module template 'module_template.tpl' use theme template 'product-list.tpl'.

 

Link to comment
Share on other sites

It work in module_name/views/templates/front  

You can try with this sample module https://github.com/frederic-benoist/fbsample_messageoftheday

In the front controller you can see :

  $this->setTemplate('module:fbsample_messageoftheday/views/templates/front/default.tpl');

And in the template :

{extends file=$layout}

{block name='content'}
  <section id="main" class="messages-list">
        <h1>{l s='Messages' mod='fbsample_messageoftheday'}</h1>
        <div class="card-columns">
        {foreach from=$messages item=message}
          <div class="card">
            <div class="card-header">{$message.title}</div>
            <div class="card-body">{$message.message|cleanHtml nofilter}</div>
          </div>
        {/foreach}
        </div>
    </section>
{/block}

 

 

Link to comment
Share on other sites

So we agree.

  • it works with extends
  • it doesn't work with include.

I think the right solution for @aymeric69001 would be:

  1. Create a template in the themes directory mytheme/templates/custom_template.tpl
  2. Create a template in the modules directory : mymodule/views/templates/front/my_controller.tpl

With in  mymodule/views/templates/front/my_controller.tpl  :

@extend "custom_template.tpl"
Link to comment
Share on other sites

Thanks, indeed it is working, but I changed my mind and would like to put these custom pages directly into my theme folder, so I will open a new thread on how to have a module belonging to the theme folder (in themes\mytheme\modules), be installed when the theme is installed.

 

But thank you anyway

 

Aymeric

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...