Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Adding classes to filter headers
 
samleaver
Member
 
Total Posts:  45
Joined:  2008-03-04
 

Hi

I would like to add classes to the filter headers, does anyone know a way of getting the filter id in the foreach loop?

for example:

Filters are pulled in by this code:

<?php if($this->canShowBlock()): ?>
<div class="block block-layered-nav">
    <
div class="block-title">
        <
strong><span><?php echo $this->__('Shop By'?></span></strong>
    </
div>
    <
div class="block-content">
        
<?php echo $this->getStateHtml() ?>
        <?php 
if ($this->getLayer()->getState()->getFilters()): ?>
            
<div class="actions"><a href="<?php echo $this->getClearUrl() ?>"><?php echo $this->__('Clear All'?></a></div>
        
<?php endif; ?>
        <?php 
if($this->canShowOptions()): ?>
            
<class="block-subtitle"><?php echo $this->__('Shopping Options'?></p>
            <
dl id="narrow-by-list">
                
<?php $_filters $this->getFilters() ?>
                <?php 
foreach ($_filters as $_filter): ?>
                <?php 
if($_filter->getItemsCount()): ?>
                    
<dt><?php echo $this->__($_filter->getName()) ?></dt>
                    <
dd><?php echo $_filter->getHtml() ?></dd>
                
<?php endif; ?>
                <?php 
endforeach; ?>
            
</dl>
            <
script type="text/javascript">decorateDataList('narrow-by-list')</script>
        <?php 
endif; ?>
    
</div>
</
div>
<?php endif; ?>

Filter headers are this line:

<dt><?php echo $this->__($_filter->getName()) ?></dt>

I would like to add a class to the dt of something like “filterid12” so that i can style them individually.

Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
samleaver
Member
 
Total Posts:  45
Joined:  2008-03-04
 

I tried this:

<dt id="filter<?php echo $this->__($_filter->getAttributeCode()) ?>"><?php echo $this->__($_filter->getName()) ?></dt>

But it doesn’t output the attribute code.

 
Magento Community Magento Community
Magento Community
Magento Community
 
samleaver
Member
 
Total Posts:  45
Joined:  2008-03-04
 

Anyone have any input? I’m a bit stumped!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Siggi_Schmitz
Enthusiast
 
Avatar
Total Posts:  811
Joined:  2011-07-03
 

Try to log or var_dump

$_filter->getData();

Then you will see all data from the filter object, there you will find what you want.

 
Magento Community Magento Community
Magento Community
Magento Community
 
samleaver
Member
 
Total Posts:  45
Joined:  2008-03-04
 

Thanks Siggi,

I’ve tried dropping in:

<?php
var_dump
($_filter->getData);
?>

But it just outputs null? am i doing something wrong?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Siggi_Schmitz
Enthusiast
 
Avatar
Total Posts:  811
Joined:  2011-07-03
 

Try to log in var/log/system.log with

Mage::log($_filter->getData());

 
Magento Community Magento Community
Magento Community
Magento Community
 
samleaver
Member
 
Total Posts:  45
Joined:  2008-03-04
 

Thanks very much for your help Siggi, but i just sorted it smile

Just incase anyone reading this wants to know how, I had to use getAttributeModel:

<dt id="filter_<?php echo $_filter->getAttributeModel()->getAttributeCode() ?>"><?php echo $this->__($_filter->getName()) ?></dt>
 
Magento Community Magento Community
Magento Community
Magento Community
 
Siggi_Schmitz
Enthusiast
 
Avatar
Total Posts:  811
Joined:  2011-07-03
 

ok, good to know grin

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top