使用模块为magento 2中的每个产品页面添加一个脚本标签


Adding a script tag to every product page in magento 2 using module

我是新手。

我从下面提到的教程中创建了一个模块-2模块。

http://inchoo.net/magento-2/how-to-create-a-basic-module-in-magento-2/

使用该模块,我将脚本注入页面。但是这样的话,我只能在我的模块页面上执行,也就是

http://localhost/magento2/helloworld

我已经安装了一个示例商店,但是如果我希望我的模块在任何产品页面上执行,我应该怎么做?

请帮助我理解。请在文章中指指点点。

谢谢。

在布局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>

我找到了解决这个特定问题的文章。

https://mage2.pro/t/topic/34

在这里他添加了默认的脚本文件,而不是通过路由。

编辑:

在另一篇文章中,他给出了有条件加载脚本和css文件的信息。

http://www.webspeaks.in/2016/03/how-to-add-css-and-js-in-magento-2-custom-module.html