Search code examples
magentomagento2magento-2.3layered-navigation

How to make dropdown layered navigation in Magento 2


I'm figuring out about Magento 2 layered navigation. I want to make this navigation with dropdown lists.

I try this code:

<select onchange="setLocation(this.value)">
 <option value=""><?php echo 'Choose an Option...' ?></option>
 <?php foreach ($this->getItems() as $_item): ?>
     <option
        <?php if ($_item->getCount() > 0): ?>
        value="<?php echo $this->urlEscape($_item->getUrl()) ?>"><?php echo $_item->getLabel() ?>
        <?php else: echo '>' . $_item->getLabel() ?>
        <?php endif; ?>
        (<?php echo $_item->getCount() ?>)
    </option>
<?php endforeach ?>
</select>

but I am getting the error "setLocation(this.value) is not defined". If anyone has another option, please let me know.


Solution

  • Please add below js code:

    function setLocation(value) {
        window.location = value;
    }