ubermanu / magento2-motu
为 Magento 2 实现的岛屿架构
1.0.1
2024-02-29 09:44 UTC
Requires
- abordage/html-min: ^0.2.2
- magento/framework: *
This package is auto-updated.
Last update: 2024-09-29 10:57:57 UTC
README
为 Magento 2 实现的岛屿模式。
岛屿架构鼓励在服务器渲染的网页中实现小型、专注的交互块。岛屿的输出是渐进式增强的 HTML,对增强过程有更具体的规定。不是单一应用程序控制整个页面的渲染,而是有多个入口点。这些“岛屿”交互的脚本可以独立交付和激活,允许页面的其余部分保持静态 HTML。
来源:岛屿架构
安装
composer require ubermanu/magento2-motu
快速开始
创建一个新的岛屿块
<?php namespace Vendor\Module\Block\Island; class Example extends \Ubermanu\Motu\View\Element\AbstractIsland { public function getClientMethod(): string { return 'load'; } }
将块添加到你的布局中
<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceContainer name="content"> <block class="Vendor\Module\Block\Island\Example" name="example" template="Vendor_Module::island/example.phtml" /> </referenceContainer> </body> </page>
就这样!岛屿将在页面中渲染并由客户端脚本激活。