3

I need to show the layer navigation filter values in above the search page heading.

enter image description here

I have tried below code in the app\design\frontend\rwd\default\template\catalogsearch\result.phtml file.

$layout         = Mage::getSingleton('core/layout');
$block_header   = $layout->createBlock('catalog/layer_state')->setTemplate('catalog/layer/state_1.phtml');
$block_links    = $layout->createBlock('core/text_list','catalog.leftnav.state.renderers');
$block_header->setChild('state_renderers',$block_links);
echo $block_header->toHtml();

But I am getting empty value.

Please assist me.

4
  • are you using third party extension or creating new one? Jan 6, 2016 at 5:40
  • I did not used any third party extension, I have created the custom attributes in backend.
    – VijayS91
    Jan 6, 2016 at 5:48
  • i think you can get value by Mage::app()->getRequest()->getParam('your params'); Jan 6, 2016 at 5:50
  • Yes its possible, But did not get correct format as per filter showing in left side navigation.
    – VijayS91
    Jan 6, 2016 at 6:08

1 Answer 1

2

you can get active filter with below code. tested code..

for category page

 <?php 
$_filters = Mage::getSingleton('catalog/layer')->getState()->getFilters();

foreach ($_filters as $_filter):?>
<?php echo $this->stripTags($_filter->getLabel()) ?><a href=”<?php echo $_filter->getRemoveUrl() ?>” title=”<?php echo $this->__('Remove This Item') ?>”><?php echo $this->__('Remove This Item') ?></a>
<?php endforeach; ?>

for search page

    <?php 
 $_filters = Mage::getSingleton('catalogsearch/layer')->getState()->getFilters();

foreach ($_filters as $_filter):?>
<?php echo $this->stripTags($_filter->getLabel()) ?><a href=”<?php echo $_filter->getRemoveUrl() ?>” title=”<?php echo $this->__('Remove This Item') ?>”><?php echo $this->__('Remove This Item') ?></a>
<?php endforeach; ?>

or you want to show only the current filter state use this code

for category page

<?php echo $this->getLayout()->createBlock('catalog/layer_state')->setTemplate('catalog/layer/state.phtml')->toHtml(); ?>

for search result

<?php echo Mage::app()->getLayout()->createBlock('catalogsearch/layer')->setTemplate('catal‌​og/layer/state.phtml')->toHtml(); ?>
7
  • I have printed the array "print_r($_filters);" I am getting empty array value.I have filtered two options (rating ,price).
    – VijayS91
    Jan 6, 2016 at 6:44
  • try it again there was error in code.. Jan 6, 2016 at 6:48
  • I am did not get error, I have print the array I am getting " Array () ".
    – VijayS91
    Jan 6, 2016 at 6:51
  • try this $appliedFilters = Mage::getSingleton('catalog/layer')->getState()->getFilters(); Jan 6, 2016 at 6:54
  • my bad luck, I am getting empty array.
    – VijayS91
    Jan 6, 2016 at 7:00

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.