I have a requirement in my project where I need to show both horizontal & vertical layered navigation in product listing page. I have tried to achieve it but facing issue of Illegal state enter image description here

I have added below code before toolbar code in list.phtml file which loads products.

<?=  $block->getLayout()->createBlock('Magento\LayeredNavigation\Block\Navigation\Category')->setTemplate("Magento_Catalog::product/list/toolbar/filter.phtml")->toHtml(); ?>

And added a custom filter.phtml file with below code:

<?php foreach ($block->getFilters() as $key => $filter): ?>
<?php if ($filter->getItemsCount()): ?>
    <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>
<?php endif; ?>

Anyone who have any idea please let me know. I want to implement as below: enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.