Then, copy the file located at "vendor\magento\theme-frontend-luma\Magento_LayeredNavigation\templates\layer\view.phtml" into the appropriate area in your child theme.
You need to change the data-mage-init attribute and the "active" property to be in a format that specifies which filters to open by their index. I have 6 filters, so I want that property to read "0 1 2 3 4 5".
I made a couple of changes between lines 30-45 and it looks like this
<?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; ?>
You need to change the data-mage-init attribute and the "active" property to be in a format that specifies which filters to open by their index. I have 6 filters, so I want that property to read "0 1 2 3 4 5".
I made a couple of changes between lines 30-45 and it looks like this
<?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; ?>
This article very helpful
ReplyDeleteThank you man :D
ReplyDelete