magento 2扩展分层导航
在Magento 2.0中,默认情况下,除了第一个过滤器(我的价格)外,分层导航全部折叠。如何展开所有过滤器,使每个过滤器选项在所有过滤器类别中都可见 我看到在代码中有aria expanded=“false”,在HTML的某处有class=“filter options content”和style=“display:none;” 有人知道在哪里编辑吗? 打开文件:## 供应商\magento\theme frontend luma\magento\u LayeredNavigation\templates\layer\view.phtml 并更改“数据图像初始化”属性,如下所示:magento 2扩展分层导航,magento,magento2,Magento,Magento2,在Magento 2.0中,默认情况下,除了第一个过滤器(我的价格)外,分层导航全部折叠。如何展开所有过滤器,使每个过滤器选项在所有过滤器类别中都可见 我看到在代码中有aria expanded=“false”,在HTML的某处有class=“filter options content”和style=“display:none;” 有人知道在哪里编辑吗? 打开文件:## 供应商\magento\theme frontend luma\magento\u LayeredNavigation\te
如果您正在使用Luma主题并希望这样做,请确保创建自己的主题作为Luma主题的子主题。你可以在这里找到更多信息()
然后,将位于“vendor\magento\theme frontend luma\magento\u LayeredNavigation\templates\layer\view.phtml”的文件复制到子主题的相应区域中
您需要将数据mage init属性和“active”属性更改为指定按其索引打开哪些过滤器的格式。我有6个筛选器,因此我希望该属性为“0 1 2 3 4 5”
我在第30-45行之间做了一些更改,看起来是这样的:
<?php $wrapOptions = false; ?>
<?php
$filters = $block->getFilters();
$active_filters_str = implode(' ', range(0, count($filters)-1));
?>
<?php foreach ($filters as $filter): ?>
<?php if ($filter->getItemsCount()): ?>
<?php if (!$wrapOptions): ?>
<div class="filter-options" id="narrow-by-list" data-role="content" data-mage-init='{"accordion":{"openedState": "active", "collapsible": true, "active": "<?php echo $active_filters_str ?>", "multipleCollapsible": true}}'>
<?php $wrapOptions = true; endif; ?>
<div data-role="collapsible" class="filter-options-item">
<div data-role="title" class="filter-options-title"><?php /* @escapeNotVerified */ echo __($filter->getName()) ?></div>
<div data-role="content" class="filter-options-content"><?php /* @escapeNotVerified */ echo $block->getChildBlock('renderer')->render($filter); ?></div>
</div>
<?php endif; ?>
<?php endforeach; ?>
首先,确保使用“$filters=$block->getFilters();”获取变量中的所有过滤器。然后,使用“$active_filters_str=infrade(“”,range(0,count($filters)-1));”为活动属性创建一个字符串,通过索引将它们列出,然后在mage init属性中的活动属性旁边回显该字符串
希望这有帮助:)非常有帮助。。工作了,但我想多了解一点。。我在
内爆(“”,范围(0,计数($filters)-1))上做了打印代码>和它吐出了大量的数字。但这正是我想要的。。如果我只是想显示第一个类别,需要做“0,1”重复答案
<?php $wrapOptions = false; ?>
<?php
$filters = $block->getFilters();
$active_filters_str = implode(' ', range(0, count($filters)-1));
?>
<?php foreach ($filters as $filter): ?>
<?php if ($filter->getItemsCount()): ?>
<?php if (!$wrapOptions): ?>
<div class="filter-options" id="narrow-by-list" data-role="content" data-mage-init='{"accordion":{"openedState": "active", "collapsible": true, "active": "<?php echo $active_filters_str ?>", "multipleCollapsible": true}}'>
<?php $wrapOptions = true; endif; ?>
<div data-role="collapsible" class="filter-options-item">
<div data-role="title" class="filter-options-title"><?php /* @escapeNotVerified */ echo __($filter->getName()) ?></div>
<div data-role="content" class="filter-options-content"><?php /* @escapeNotVerified */ echo $block->getChildBlock('renderer')->render($filter); ?></div>
</div>
<?php endif; ?>
<?php endforeach; ?>