Broken html script - does Incapsula change the html tags positions?

136 views Asked by At

I am using Magento2 with fpc, varnish, redis and Incapsula, and I am facing a very strange behaviour for a broken html content. I have a phtml file containing some php followed by javascript as follows:

<div class="some-class">
 <!--html -->
 </div>
 <script>
 //...
$element.wrap('<div class="red"></div>');
//..
</script>

In a parent template (also phtml file), this file is being included using php include (yes this is how a Magento core module including it without using blocks) as:

<?php include 'path/to/file.phtml'; ?>

The problem is that on the page source I am getting the following unexpected html:

<div class="some-class">
<!--html -->
</div>
<script>
//...
$element.wrap('<div class="red"></script></div>');
//..broken content here due to the moved script tag

Notice the moved ending tag ..

I know that this scenario can happen due to several issues, but I am suspecting Incapsula because its being used by the only environment where the issue occurs

Please suggest possible scenarios related to caching, any help or idea is appreciated.

Thanks

1

There are 1 answers

1
rangerz On

Try to use this way to echo other phtml in phtml.

<?php
echo $block->getLayout()
    ->createBlock("Magento\Framework\View\Element\Template")
    ->setTemplate("Your_Module::file.phtml")
    ->toHtml();
?>