In this post I am going to explain How to check IsHomePage in Magento 2.
Add below code snippet in Block class.
protected $_logo;
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Theme\Block\Html\Header\Logo $logo,
array $data = []
)
{
$this->_logo = $logo;
parent::__construct($context, $data);
}
public function isHomePage() {
return $this->_logo->isHomePage();
}
Add below code snippet in template file.
if ($block->isHomePage()) {
// do something
}
Thats it. Enjoy Magento 2!!
Write an article about ecommerce that help people to grow their ecommerce business. You’ll find best ecommerce guide, news, tips & more!


Leave a Reply