Jump to content

How to call TPL from controller? Problem in RC2 and RC3


Andrej Stas

Recommended Posts

We are developing Blog Module for Prestashop 1.7.

 

This is our new problem now:

 

in our_module/controllers/front/some_file.php we call $this->setTemplate('blog.tpl');

 

Blog.tpl really exists: our_module/views/templates/front/blog.tpl

 

However, we are getting this error (see screenshot)

 

This is working correctly in RC1, not working in RC2

 

EDIT: not working also in RC3

post-48475-0-49633400-1476968819_thumb.png

Edited by Andrej Stas (see edit history)
  • Like 2
Link to comment
Share on other sites

  • 2 weeks later...

You are right, it should be written as "blog" instead of "blog.tpl", but my problem still persists.

 

I found out that Prestashop is always searching for this "blog.tpl" only in the "theme" folder. But in my case, the TPL files are saved in the module folder our_module/views/templates/front/blog.tpl

Link to comment
Share on other sites

Hello!

 

I got the same problem. setTemplate() tries to find the template file in the theme directory. More specifically, in "templates/fr-FR" (or "templates/en-EN", "templates/es-ES"... depend on the shop language).

 

Are we supposed to use another function to load templates in 1.7?

Link to comment
Share on other sites

 

I thought that fetch() was meant to replace display(), as it returns the content of the template.

setTemplate() is a method of ModuleFrontController class, usually use in the initContent() method, it does not directly return the content of the template. 

 

I'm a little bit confused :s

Link to comment
Share on other sites

Yes you are right my bad.

 

In initContent() method maybe something like this 

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

Example also in

 

https://github.com/PrestaShop/ps_emailsubscription/blob/master/controllers/front/verification.php#L50

 

And about languages not sure how it is for module but here is some info about template hierarchy, but 

as I understand for themes mostly.

 

https://github.com/PrestaShop/PrestaShop/pull/5809 

  • Like 1
Link to comment
Share on other sites

I tried with a path like 'module:our_module/views/templates/front/blog.tpl' : It loads the template, but not the layout. I only got the template content, nothing else, no css, no js, not a single piece of the theme html.

 

And I can't find any parameter for initContent or setTemplate that specify if we want just the template or the whole page.

 

What am I doing wrong?

Edited by Yoddle (see edit history)
Link to comment
Share on other sites

 

 

Thanks! But is it the official new way to deal with template in module front controller or just a work around?

 

In the new 1.7 dev documentation (http://developers.prestashop.com/module/05-CreatingAPrestaShop17Module/05-DisplayingContentOnTheFrontOffice.html), as far as I understand, setTemplate is supposed to work exactly like in 1.6

 

Any way to get an official answer?

Link to comment
Share on other sites

  • 3 months later...

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...