I want to call layer navigation in my custom page
<?php
namespace MPS\Allproduct\Block\Index;
use Magento\Catalog\Api\CategoryRepositoryInterface;
use Magento\Catalog\Model\Category;
use Magento\Catalog\Block\Product\AbstractProduct;
use Magento\Catalog\Model\Product;
use Magento\Eav\Model\Entity\Collection\AbstractCollection;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\DataObject\IdentityInterface;
use Magento\Customer\Model\Context as CustomerContext;
class Index extends \Magento\Framework\View\Element\Template {
protected $urlHelper;
public function __construct(
\Magento\Directory\Model\Currency $currency,
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
\Magento\Catalog\Block\Product\Context $context,
\Magento\Framework\Data\Helper\PostHelper $postDataHelper,
\Magento\Catalog\Model\Layer\Resolver $layerResolver,
CategoryRepositoryInterface $categoryRepository,
\Magento\Catalog\Model\CategoryFactory $categoryFactory,
\Magento\Framework\Url\Helper\Data $urlHelper,
\Magento\Framework\Data\Form\FormKey $formKey,
array $data = []
)
{
$this->_categoryFactory = $categoryFactory;
$this->_currency = $currency;
$this->_catalogLayer = $layerResolver->get();
$this->_postDataHelper = $postDataHelper;
$this->categoryRepository = $categoryRepository;
$this->urlHelper = $urlHelper;
$this->_productCollectionFactory = $productCollectionFactory;
$this->formKey = $formKey;
parent::__construct($context, $data);
}
public function getAddToCartPostParams(\Magento\Catalog\Model\Product $_product)
{
$url = $this->getAddToCartUrl($_product);
return [
'action' => $url,
'data' => [
'product' => $_product->getEntityId(),
\Magento\Framework\App\ActionInterface::PARAM_NAME_URL_ENCODED =>
$this->urlHelper->getEncodedUrl($url),
]
];
}
public function getNewProductCollection()
{
$collection = $this->_productCollectionFactory->create();
$collection->addAttributeToSelect('*');
/*$collection->setPageSize(4);*/
$collection->setOrder('entity_id','DESC');
return $collection;
}
public function getFormKey()
{
return $this->formKey->getFormKey();
}
}
xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
<head>
<title>Titlename</title>
</head>
<body>
<referenceContainer name="sidebar.main">
<block class="MPS\Allproduct\Block\Index\Sidebar" name="allproduct_index_sidebar" before="-" template="MPS_Allproduct::allproduct_index_sidebar.phtml"/>
</referenceContainer>
<referenceContainer name="content">
<block class="MPS\Allproduct\Block\Index\Index" name="allproduct_index_index" template="MPS_Allproduct::allproduct_index_index.phtml"/>
</referenceContainer>
</body>
</page>
How to achieve this?