Magento get attribute code from filter.phtml
I am trying to get the attribute code from the filter.phtm开发者_运维百科l template file. Does anyone have any ideas how to do this?
$_item->getFilter()->getAttributeModel()->getAttributeCode()
The above line of code can be used to get the attribute code when it is in the loop.
It will works only if filter is attribute bu for category it will not work so you have to write like
echo $_filter->getType();
if($_filter->getType()=='catalog/layer_filter_attribute')
{
echo $_filter->getAttributeModel()->getAttributeCode();
}
Based on @Posuk13 comment at @Darren's answer, but to get the attribute code outside the items loop, you could use:
$this->getFilter()->getRequestVar()
(Tested on Magento 1.9 Community Edition)
Specifically in the context of $this being the class in use in filter.phtml the following prints/returns the attribute code:-
<?php echo $this->getAttributeModel()->getAttributeCode() ?>
精彩评论