0

I have a modal that pops up when the site detects it's on IE11. The modal is in a cms block so that the client can edit it. I have created a reference container with a custom phtml and put the script in there. But it's not working! Is this because the script is in a phtml file? and if so can I call a block using php in a js file? Please note that I'm trying to detect chrome in this example as I'm on a mac.

<script type="text/javascript"> document.addEventListener("DOMContentLoaded", function(){ if (!navigator.userAgent.includes('Chrome')) { <?php echo $this->getLayout() ->createBlock('Magento\Cms\Block\Block') ->setBlockId('dontuseie') ->toHtml(); ?> } }); </script>

1 Answer 1

1

Scripts in CMS Blocks sounds like something that Magento would block.

If it is just the content of the "dontuseie" block that needs to be admin-editable, you could:

  1. Render that block in a hidden div.
  2. Show the div where applicable using a script included by the supported Magento methods (source code or Scripts and Style Sheets).
1
  • Thank you for the workaround, that worked a treat.
    – totneschap
    Commented Oct 11, 2021 at 9:35

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.