使用模块向 magento 2 中的每个产品页面添加脚本标签
Adding a script tag to every product page in magento 2 using module
我是 magento 新手。
我根据下面提到的教程创建了一个 module-2 模块。
http://inchoo.net/magento-2/how-to-create-a-basic-module-in-magento-2/
使用该模块,我将脚本注入页面。但是有了这个,我只能在我的模块页面上执行,即
http://localhost/magento2/helloworld
我安装了一个示例商店,但是如果我想让我的模块在任何产品页面上执行,我应该怎么做。
请帮我理解。指点文章将不胜感激。
谢谢。
我找到了解决这个特定问题的文章。
在这里他默认添加了脚本文件,而不是通过路由。
编辑:
在另一篇文章中,他提供了有关脚本和 css 文件的条件加载的信息。
http://www.webspeaks.in/2016/03/how-to-add-css-and-js-in-magento-2-custom-module.html
在布局 xml 的标记内调用您的 css 和 js 文件。
示例:
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-1column" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
<head>
<link src="Namespace_YourModule::script.js"/>
<css src="Namespace_YourModule::style.css"/>
</head>
<body>
</body>
</page>
我是 magento 新手。
我根据下面提到的教程创建了一个 module-2 模块。
http://inchoo.net/magento-2/how-to-create-a-basic-module-in-magento-2/
使用该模块,我将脚本注入页面。但是有了这个,我只能在我的模块页面上执行,即
http://localhost/magento2/helloworld
我安装了一个示例商店,但是如果我想让我的模块在任何产品页面上执行,我应该怎么做。
请帮我理解。指点文章将不胜感激。
谢谢。
我找到了解决这个特定问题的文章。
在这里他默认添加了脚本文件,而不是通过路由。
编辑: 在另一篇文章中,他提供了有关脚本和 css 文件的条件加载的信息。
http://www.webspeaks.in/2016/03/how-to-add-css-and-js-in-magento-2-custom-module.html
在布局 xml 的标记内调用您的 css 和 js 文件。 示例:
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-1column" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
<head>
<link src="Namespace_YourModule::script.js"/>
<css src="Namespace_YourModule::style.css"/>
</head>
<body>
</body>
</page>