On my Drupal 8.9 site I have the Drupal Commerce module. I created a custom module to create new pages in the store path, which also uses its own template files.

How do I the Twig variables of a store in a custom module?

For example in the store template file (commerce-store--professionnel--full.html.twig), I can print the store type with this code.

{{ store_entity.type.entity.label }}

In the template file of my custom module, it doesn't work.

  • 1
    Unfortunately, twig doesn't quite work like that. Each twig template file has its own set of variables. These variables depend on how the twig file has been implemented. You can always put {{ dump() }} inside your twig template - or even better get a debugger set up. More info can be found here: drupal.org/docs/theming-drupal/twig-in-drupal/… - good luck! – 100pic Jul 1 at 23:03
  • @100pic Thank you, when I put {{dump ()}} in my TWIG I have a blank page. I activated debug in service – mathieu Jul 1 at 23:31
  • @100pic If I {{ dump(title) }} the page displays NULL – mathieu Jul 1 at 23:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.