magento 2扩展分层导航

JTu*_*JTu 0 magento magento2

在Magento 2.0中,默认情况下分层导航全部折叠,但第一个过滤器除外,这对我来说是价格.如何展开所有过滤器,以便在所有过滤器类别中都显示每个过滤器选项?

我在代码中看到aria-expanded ="false",在HTML的某个地方有class ="filter-options-content",style ="display:none;"

有谁知道在哪里编辑这个?

BVB*_*ate 5

如果您正在使用Luma主题并希望这样做,请确保创建自己的主题作为Luma主题的孩子.你可以在这里找到更多相关信息(https://community.magento.com/t5/Theming-Layout-Design-Questions/How-to-create-a-Child-Theme-in-Magento-2/mp/33314 #M384)

然后,将位于"vendor\magento\theme-frontend-luma\Magento_LayeredNavigation\templates\layer\view.phtml"的文件复制到子主题中的相应区域.

您需要将data-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; ?>
Run Code Online (Sandbox Code Playgroud)

首先,确保使用"$ filters = $ block-> getFilters();"获取变量中的所有过滤器.然后,为活动属性创建一个字符串,使用"$ active_filters_str = implode('',range(0,count($ filters)-1))索引它们;" 然后在mage-init属性中的active属性旁边回显它.

希望这可以帮助 :)