derfuchs / magento2-morelayouthandles
为 Magento 2 添加更多有用的布局处理程序
1.0.0
2020-12-09 13:30 UTC
Requires
- magento/framework: ~100.0.0
README
Magento 2 - 更多布局处理程序
为 Magento 2 获取更多有用的布局处理程序
探索文档
报告错误 · 请求功能
关于此项目
此模块动态地为特定的 Magento 2 页面添加一些布局处理程序。
当您想更改布局时,这非常有用,例如移除一些块或将它们移动到另一个位置,但您希望它们仅在特定页面或特定产品、属性集等情况下可用。有关当前模块版本中可能实现的内容,请参阅可用的布局处理程序。
适用于
- Magento 2,在 2.4.x 版本上进行了测试
安装
此模块作为 Magento 2 的 composer 模块提供
- 使用 composer 将其安装到您的 Magento 2 中
composer require derfuchs/magento2-morelayouthandles
- 升级 Magento 2
bin/magento setup:upgrade
- 重新编译 Magento 的依赖注入
bin/magento setup:di:compile
使用
在 Magento 管理面板的此模块配置部分中启用您想要启用的每个布局处理程序。然后在布局 xml 文件中设置您的布局更新
- 启用您想要使用的布局处理程序:
Magento 管理员 -> 店铺 -> 配置 -> 一般 -> 更多布局处理程序
- 通过使用开发者工具栏或启用此模块的调试输出来检查新布局处理程序是否出现:
Magento 管理员 -> 店铺 -> 配置 -> 一般 -> 更多布局处理程序 -> 一般设置 -> 调试
- 创建一个名为结果布局处理程序的新文件,例如
<magento_root>/app/design/frontend/<vendor_name>/<theme_name>/Magento_Theme/layout/<layout_handle_name>.xml
(您不必使用 Magento_Theme 文件夹,这只是一个示例) - 开始编写您的布局更新 XML。您可以自由使用此模板作为起点
<?xml version="1.0"?> <!-- /** * Some useful hints about what this layout update file does */ --> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <!-- reference a container or a block or whatever. See Magento's layout instruction documentation for more information: https://devdocs.magento.com/guides/v2.4/frontend-dev-guide/layouts/xml-instructions.html --> <referenceContainer name="container.name.you.want.to.reference"> <!-- do stuff --> </referenceContainer> </body> </page>
- 清除缓存:
bin/magento cache:clean
就是这样。当布局处理程序出现时,Magento 将烘焙您的布局更新。
可用的布局处理程序
这是一个所有可能布局处理程序的列表
产品的属性集 ID
- 在产品详细页面上可用
- 布局处理程序名称:catalog_product_view_attribute_set_id_(属性集-id)
产品的属性集名称
- 在产品详细页面上可用
- 布局处理程序名称:catalog_product_view_attribute_set_name_(属性集名称)
没有找到您需要的内容?
请随时请求实现或自行实现(并通过拉取请求让其他人参与 :) )。
路线图
请参阅开放问题以获取功能建议(和已知问题)的列表。
即将推出的版本 1.1
在特定产品属性出现时添加布局处理程序
最新版本 1.0
产品页面上产品的属性集 ID 和属性集名称的布局处理程序
贡献
贡献使开源社区成为学习、灵感和创作的绝佳场所。您做出的任何贡献都深受欢迎。
- 分支项目
- 创建功能分支(
git checkout -b feature/AmazingFeature
) - 提交您的更改(
git commit -m '添加一些AmazingFeature'
) - 推送到分支(
git push origin feature/AmazingFeature
) - 打开Pull Request
许可
采用MIT许可证发布。有关更多信息,请参阅LICENSE
文件。
联系
Michael Fuchs - derfuchs - michael@derfuchs.net