I am displayed the tier price like table structure in Category List/Grid Mode successfully. Now I am trying to disable the table structure in Category Grid Mode. But I can't get the category view mode $block->getMode() in root/module-catalog/view/base/templates/product/price/final_price.phtml file.

Category List Mode

enter image description here

Category Grid Mode

enter image description here

In Grid Mode UI not well so I need to disable or need to show normal price. So how to get the Category page view mode in this file. So that I can write logic on this page.

Any help on this?


You can't get direct mode in final_price.phtml because in \Magento\Framework\Pricing\Render\RendererPool Magento doesn't set any child toolbar block.

In list page you are getting because when you look at \Magento\Catalog\Block\Product\ListProduct there is one method available for that

public function getMode()
        return $this->getChildBlock('toolbar')->getCurrentMode();

It means Magento using toolbar block for that.

I am not sure how you are changing final_price.phtml and which block you are using, But if you are using custom block then you can simple achieve by injecting toolbar block in constructor.

namespace Test\Module\Block;

class Product extends \Magento\Framework\View\Element\Template

  protected $_toolbar;  

  public function __construct(
        \Magento\Catalog\Block\Product\ProductList\Toolbar $_toolbar
    ) {
        $this->_toolbar = $_toolbar;
    public function getMode()
        return $this->_toolbar->getCurrentMode();


Now you can access $block->getMode() in phtml files.

Dirty way

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$modecheck = $objectManager->create('Magento\Catalog\Block\Product\ProductList\Toolbar')->getCurrentMode();

In $modecheck variable you can get current mode.

Note: I am against of direct loading object with objectManager, for better impact you can inject it in your constructor

| improve this answer | |
  • I am using registry to get the view mode from list.phtml first time working next time I mean when I changing Grid Mode not updating the log. I figured that next time on wards it's rendering from cache. $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $registry = $objectManager->get('Magento\Framework\Registry'); $registry->register('Category_Page_View_Mode', $block->getMode());$view_Mode = $registry->registry('Category_Page_View_Mode') So how to do this? – Bojjaiah Nov 16 '16 at 9:14
  • 1
    Instead of $registry = $objectManager->get('Magento\Framework\Registry'); try with the $registry = $objectManager->create('Magento\Framework\Registry'); – Keyur Shah Nov 16 '16 at 9:16
  • let me check and get back to you – Bojjaiah Nov 16 '16 at 9:17
  • it's working only first time. even though not updating log \file_put_contents('ViewMode.txt', print_r("\n" . $mode_check,true), FILE_APPEND); when I changed the view Modes. But when I Refresh the cache it's working @ first time. – Bojjaiah Nov 16 '16 at 9:20
  • What is the $mode_check ? And If you are using mine code then you can slice change my code $modecheck = $objectManager->create('Magento\Catalog\Block\Product\ProductList\Toolbar')->getCurrentMode(); – Keyur Shah Nov 16 '16 at 9:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.