Magento: What Module is Loading the Page

One of our clients requested that the header above the filters in the left column be changed to say something else when a user is on a search results page, versus if they were just browsing the catalog. Instead of doing something janky like scrubbing the url for ‘catalogsearch’, there is a much better way to do it in Magento. You can get the module name.

In my case, this worked perfectly (which I put in …/template/catalog/layer/view.phtml):

<?php $_currentModule = $this->getRequest()->getModuleName(); ?>
<?php if ($_currentModule == 'catalogsearch') : ?>
    <p class="block-subtitle"><?php echo $this->__('Narrow Your Results') ?></p>
<?php else : ?>
    <p class="block-subtitle"><?php echo $this->__('Filter Products') ?></p>
<?php endif; ?>

If you are browsing the catalog, you will be within the ‘catalog’ module. If you are in the search results, you’ll be within the ‘catalogsearch’ module.

That specific code works great in templates. However, it may not work properly in some class files. You may want to try this instead:

This entry was posted in Magento. Bookmark the permalink.

Comments are closed.