Magento 2:如何在 CMS 页面中的 body 标记结束之前添加自定义 js 文件
Magento 2: How to add a custom js file before end of body tag in CMS page
Magento 文档不包含此基本功能。
尝试以下步骤在 body 标签前添加自定义 js
第 1 步:将以下布局代码添加到 myvendor/mytheme/Magento_Theme/layout/default.xml
<referenceContainer name="before.body.end">
<block class="\Magento\Framework\View\Element\Template" template="You_Module::js.phtml" name="module_js"/>
</referenceContainer>
第 2 步:在 js.phtml 文件中添加 custom.js,如下所示。
<script src="example.com/jp2/test.js" />
Magento 文档不包含此基本功能。
尝试以下步骤在 body 标签前添加自定义 js
第 1 步:将以下布局代码添加到 myvendor/mytheme/Magento_Theme/layout/default.xml
<referenceContainer name="before.body.end">
<block class="\Magento\Framework\View\Element\Template" template="You_Module::js.phtml" name="module_js"/>
</referenceContainer>
第 2 步:在 js.phtml 文件中添加 custom.js,如下所示。
<script src="example.com/jp2/test.js" />