Jump to content

I have a custom module and I'm trying to extends a Twig template in the product view, but I'm encountering issues with extending the Twig in the product's view.


Mac Story

Recommended Posts

Hello,

Your problem is most likely the fact that you are using the display method, or some similar method, which should be used only for smarty templates.

For twig templates, you need to use the render method.

If you are in a module main file, here is the syntax that you need to use: 

return $this->get('twig')->render('@Modules/<module_name>/views/templates/admin/test.twig', []);

You will need to replace that first argument with your information. The array is the data passed to the template.

If you are in an admin controller that extends FrameworkBundleAdminController, you directly have access to the render method.

  • Thanks 1
Link to comment
Share on other sites

  On 9/5/2024 at 5:56 AM, Andrei H said:

Hello,

Your problem is most likely the fact that you are using the display method, or some similar method, which should be used only for smarty templates.

For twig templates, you need to use the render method.

If you are in a module main file, here is the syntax that you need to use: 

return $this->get('twig')->render('@Modules/<module_name>/views/templates/admin/test.twig', []);

You will need to replace that first argument with your information. The array is the data passed to the template.

If you are in an admin controller that extends FrameworkBundleAdminController, you directly have access to the render method.

Expand  

Thanks! This one worked for me.

  • Like 1
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...