Question

Is it possible to open category filters in the left pane by default in Magento 2 Luma theme.

Was it helpful?

Solution

Just copy

vendor\magento\theme-frontend-luma\Magento_LayeredNavigation\templates\layer\view.phtml

into

app\design\frontend\<your_company>\<your_theme>\Magento_LayeredNavigation\templates\layer\

and change the 'data-mage-init' attribute as follow:

<?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; ?>
 <?php endforeach; ?>

OTHER TIPS

I did not test it but I think if you change line 12 to true it should work.

https://github.com/magento/magento2/blob/077584c99ebb8007cad176c3b9a0144a05c259cd/app/code/Magento/Ui/view/base/web/js/lib/collapsible.js#L12

I don't know what the proper way to override js files in Magento 2 is yet. So you should look that up to do it the Magento way.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top