Hi,
I Wanted to bring filter items in filter.phtml to view.phtml (Layered navigation), to check the getCount(); can anyone help me
\Magento\LayeredNavigation\view\frontend\template\layer
filter.phtml
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile
?>
<?php
/**
* Template for filter items block
*
* @var $block \Magento\LayeredNavigation\Block\Navigation\FilterRenderer
*/
?>
<ol class="items">
<?php foreach ($filterItems as $filterItem): ?>
<li class="item">
<?php if ($filterItem->getCount() > 0): ?>
<a href="<?= $block->escapeUrl($filterItem->getUrl()) ?>">
<?= /* @escapeNotVerified */ $filterItem->getLabel() ?>
<?php if ($this->helper('\Magento\Catalog\Helper\Data')->shouldDisplayProductCountOnLayer()): ?>
<span class="count"><?= /* @escapeNotVerified */ $filterItem->getCount() ?><span class="filter-count-label">
<?php if ($filterItem->getCount() == 1):?> <?= /* @escapeNotVerified */ __('item') ?><?php else:?> <?= /* @escapeNotVerified */ __('items') ?><?php endif;?></span></span>
<?php endif; ?>
</a>
<?php else:?>
<?= /* @escapeNotVerified */ $filterItem->getLabel() ?>
<?php if ($this->helper('\Magento\Catalog\Helper\Data')->shouldDisplayProductCountOnLayer()): ?>
<span class="count"><?= /* @escapeNotVerified */ $filterItem->getCount() ?><span class="filter-count-label">
<?php if ($filterItem->getCount() == 1):?><?= /* @escapeNotVerified */ __('item') ?><?php else:?><?= /* @escapeNotVerified */ __('items') ?><?php endif;?></span></span>
<?php endif; ?>
<?php endif; ?>
</li>
<?php endforeach ?>
</ol>
view.phtml
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile
?>
<?php
/**
* Category layered navigation
*
* @var $block \Magento\LayeredNavigation\Block\Navigation
*/
?>
<?php
if ($block->canShowBlock()):
?>
<div class="block filter">
<div class="block-title filter-title">
<strong><?= /* @escapeNotVerified */ __('Shop By') ?></strong>
</div>
<div class="block-content filter-content">
<?= $block->getChildHtml('state') ?>
<?php if ($block->getLayer()->getState()->getFilters()): ?>
<div class="block-actions filter-actions">
<a href="<?= /* @escapeNotVerified */ $block->getClearUrl() ?>" class="action clear filter-clear"><span><?= /* @escapeNotVerified */ __('Clear All') ?></span></a>
</div>
<?php endif; ?>
<?php $wrapOptions = false; ?>
<?php foreach ($block->getFilters() as $filter): ?>
<?php if (!$wrapOptions): ?>
<strong role="heading" aria-level="2" class="block-subtitle filter-subtitle"><?= /* @escapeNotVerified */ __('Shopping Options') ?></strong>
<dl class="filter-options" id="narrow-by-list">
<?php $wrapOptions = true;
endif; ?>
<?php if ($filter->getItemsCount()): ?>
<dt role="heading" aria-level="3" class="filter-options-title"><?= $block->escapeHtml(__($filter->getName())) ?></dt>
<dd class="filter-options-content"><?= /* @escapeNotVerified */ $block->getChildBlock('renderer')->render($filter) ?></dd>
<?php endif; ?>
<?php endforeach; ?>
<?php if ($wrapOptions): ?>
</dl>
<?php endif; ?>
</div>
</div>
<?php endif; ?>