list - Magento 2 - How to have 2 separates phtml to handle products list and products grid?
问题描述
I'm building a new website based on Magento 2. I'm still learning this CMS and I'm wondering one thing. Based on the webdesigner's work I've too many differences between the grid layout of the product list and the list one.
For now, to style the product grid, I've duplicate and edit this file :
app/design/frontend/MYTHEME/default/Magento_Catalog/templates/product/list.phtml
But it handle both grid and list layout, of course :
<div class="products wrapper <?= /* @noEscape */ $viewMode ?> products-<?= /* @noEscape */ $viewMode ?>">
I need to move too many things for the list layout so I try to have 2 separate phtml, one for the list layout and one for the grid layout. Is it possible, for example defining things in app/design/frontend/MYTHEME/default/Magento_Catalog/layout/catalog_category_view.xml
I guess ?
Thanks for your help.
解决方案
In your phtml file:
app/design/frontend/MYTHEME/default/Magento_Catalog/templates/product/list.phtml
Why don't you just do something like this:
<?php if ($viewMode == 'grid') :?>
// Grid layout
<?php else :?>
// List layout
<?php endif; ?>
推荐阅读
- javascript - Chart.js 在悬停时显示旧图表
- elasticsearch - Elasticsearch 管道搜索?
- adsense-api - 为什么 AdSense 网络界面和 API 报告的数字不同?
- ajax - 如何将codeigniter与ajax连接起来
- apache-kafka - 卡夫卡不开始空白输出
- python - 将 zbar 实施到 pyinstaller - Exe 不工作
- php - Wordpress:找不到 PHP 脚本 HTTP 404 错误
- java - PageNotFound:1136 - 在名为“spring”的 DispatcherServlet 中找不到具有 URI [] 的 HTTP 请求的映射
- ocaml - 这不是一个函数;不能应用
- visual-studio-code - 如何忽略非缩小文件上传?