![](/img/trans.png)
[英]Is it possible to cache JS inside <script/> tags on HTML page?
[英]Broken html script - does Incapsula change the html tags positions?
我正在将 Magento2 与 fpc、varnish、redis 和 Incapsula 一起使用,并且由于 html 内容损坏,我面临着非常奇怪的行为。 我有一个包含一些 php 后跟 javascript 的 phtml 文件,如下所示:
<div class="some-class">
<!--html -->
</div>
<script>
//...
$element.wrap('<div class="red"></div>');
//..
</script>
在父模板(也是 phtml 文件)中,使用 php include 包含此文件(是的,这是 Magento 核心模块在不使用块的情况下包含它的方式),如下所示:
<?php include 'path/to/file.phtml'; ?>
问题是在页面源上我得到了以下意外的 html:
<div class="some-class">
<!--html -->
</div>
<script>
//...
$element.wrap('<div class="red"></script></div>');
//..broken content here due to the moved script tag
注意移动的结束标签 ..
我知道这种情况可能由于几个问题而发生,但我怀疑 Incapsula 因为它被唯一发生问题的环境使用
请提出与缓存相关的可能方案,任何帮助或想法表示赞赏。
谢谢
尝试用这种方式回显phtml中的其他phtml。
<?php
echo $block->getLayout()
->createBlock("Magento\Framework\View\Element\Template")
->setTemplate("Your_Module::file.phtml")
->toHtml();
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.