Magento gets attribute code from filter.phtml file

I am trying to get the attribute code from the template.phtml file. Does anyone have any ideas how to do this?

+4
source share
3 answers

$_item->getFilter()->getAttributeModel()->getAttributeCode()

The above line of code can be used to get the attribute code when it is in a loop.

+14
source

It will work only if the filter is a bu attribute for the category, it will not work, so you need to write, for example

 echo $_filter->getType(); if($_filter->getType()=='catalog/layer_filter_attribute') { echo $_filter->getAttributeModel()->getAttributeCode(); } 
+2
source

Based on @ Posuk13, comment on @ Darren 's answer , but to get the attribute code outside the element loop, you can use:

 $this->getFilter()->getRequestVar() 

(Tested on Magento 1.9 Community Edition)

+1
source

All Articles