[英]magento 2 expand layered navigation
在Magento 2.0中,默認設置是分層導航全部折疊,除了第一個過濾器(對我來說是價格)。 如何展開所有過濾器,以便每個過濾器選項在所有過濾器類別中可見?
我在代碼中看到aria-expanded =“ false”,在HTML的某個地方有class =“ filter-options-content”和style =“ display:none;”。
有人知道在哪里編輯嗎?
如果您正在使用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; ?>
首先,確保使用“ $ filters = $ block-> getFilters();”將所有過濾器獲取到變量中。 然后,使用“ $ active_filters_str = implode('',range(0,count($ filters)-1));為活動屬性創建一個字符串,按索引列出它們 然后在mage-init屬性中的active屬性旁邊回顯此內容。
希望這可以幫助 :)
https://magento.stackexchange.com/questions/102259/open-category-filters-by-default-in-magento-2
vendor \\ magento \\ theme-frontend-luma \\ Magento_LayeredNavigation \\ templates \\ layer \\ view.phtml
<?php foreach ($block->getFilters() as $filter): ?>
<?php if ($filter->getItemsCount()): ?>
<?php if (!$wrapOptions): ?>
<?php $collapsibleRange = implode(' ', range(0, $filter->getItemsCount())); ?>
<strong role="heading" aria-level="2" class="block-subtitle filter-subtitle"><?php /* @escapeNotVerified */ echo __('Shopping Options') ?></strong>
<div class="filter-options" id="narrow-by-list" data-role="content" data-mage-init='{"accordion":{"openedState": "active", "collapsible": true, "active": "<?php echo $collapsibleRange ?>", "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; ?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.