I tried to integrate Klaro consent in Magento 2.4.2 using two phtml-files that are loaded in the right order. In a test html-file the cookie consent is shown properly.

Both js-files are loaded in Magento and output a console.log. But the Cookie consent is not shown at all. All caches (Magento and browser) are cleared – the console does not show any js-error. Any idea what could be the problem?

1 Answer 1


Finally I managed to find a solution:

  1. I created a phtml-file with the config-script and integrated it in defaul.xml with
<referenceContainer name="whateveryouwant">
    <block class="Magento\Framework\View\Element\Template" name="klaro.config" template="Magento_Theme::html/klaro-config.phtml"/>
  1. In the modules requirejs-config.js I added the klaro.js
"map": {
     "*": {
          "klaro": "sources/klaro/klaro",
  1. Finally I started Klaro in my main.js with
require(['klaro'],function(klaro) {
   window.klaro = klaro; 

Final note: The CSS can be added default.xml. Also it is recommended to create a module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.