m2-模板/模块链接预加载

允许使用预加载属性加载资源的 Magento 2 模块

安装: 17

依赖: 0

建议: 0

安全: 0

星标: 3

关注者: 1

分支: 17

开放问题: 0

类型:magento2-module

2.0.0 2020-08-09 16:37 UTC

This package is auto-updated.

Last update: 2024-09-10 16:22:22 UTC


README

这是一个简单的模块,允许在 Magento 2 中预加载资源(CSS、字体、脚本等...)

安装

  1. 前往您的 Magento 根目录
  2. 运行 composer require m2-boilerplate/module-link-preload

使用方法

要将资源添加到块中,请提供 assets 参数

<referenceBlock name="head.csspreload">
    <arguments>
        <argument name="assets" xsi:type="array">
            <item name="unique_name" xsi:type="array">
                <item name="path" xsi:type="string">css/filename.css</item>
                <item name="as" xsi:type="string">style</item>
                <item name="attributes" xsi:type="array">
                    <item name="name1" xsi:type="string">value1</item>
                    <item name="name2" xsi:type="string">value2</item>
                </item>
            </item>
        </argument>
    </arguments>
</referenceBlock>

要修改生成的 <link /> 标签的模板,请提供一个 link_template 参数,例如

<referenceBlock name="head.csspreload">
    <arguments>
        <argument name="link_template" xsi:type="string"><![CDATA[<link rel="preload" as=":as:" href=":path:" :attributes: />]]></argument>
    </arguments>
</referenceBlock>

有三个变量将被替换::path: 将被替换为资源路径,:as: 将被替换为资源类型,:attributes: 将包含您的 attributes 作为 HTML 属性。