In this post I am going to explain How to check IsHomePage in Magento 2.
Add below code snippet in Block class.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | 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.
1 2 3 | 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