Jump to content

Using Twig tmplate from a module hook in 1.7.6

Recommended Posts

Hi All,

In previous version of PS, I could render a smarty template from a hook like:

            return $this->display(__FILE__, 'assets-customers.tpl');

and the view file would be placed in modules\foo\views\templates\hook\assets-customers.tpl

The page https://devdocs.prestashop.com/1.7/modules/concepts/hooks/use-hooks-on-modern-pages/ tells us the new styntax for rendering a twig template:

    return $this->get('twig')->render('assets-customers.twig',[

But it doesn't give any clues as to where the template file should live?

I've tried it in modules\foo\, modules\foo\views\ & modules\foo\views\templates\hook\ but I awlays get

Template "assets-customers.twig" is not defined.

Can anyone share a working example of using a Twig template from a hook in a module pls? (Not overriding a built-in template)


Share this post

Link to post
Share on other sites

Aha! For anyone else with this problem, I've been poking in the prestashop files and found they've defined a Modules path in Twig. 

So you can do

    return $this->get('twig')->render('@Modules/foo/views/assets-customers.twig',[

and then put your twig file in modules/foo/views/

  • Like 1

Share this post

Link to post
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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More