I want to get the category level in product/list.phtml to check

if (categorylevel == 1)
    hide product list
    show product list

How can I do that?

Any helps? Thank in advance.

2 Answers 2


Please try with below code :

     $level= $this->getCurrentCategory()->getLevel();
     echo $level;

hope its work for you...


You can create a helper class to get current category information as given below:


namespace Amit\Test\Helper;
class Data extends \Magento\Framework\App\Helper\AbstractHelper {

    public function __construct(
        \Magento\Catalog\Model\Layer\Resolver $layerResolver
        ) {
                $this->layerResolver = $layerResolver;

    public function getCategory() {
        return $this->layerResolver->get()->getCurrentCategory();

And get the category level in product/list.phtml using below code

$testHelper = $this->helper('Amit\Test\Helper\Data');
$catLevel = $testHelper->getCategory()->getLevel();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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