Try the Demo

Magento Forum

   
Adding classes to filter headers
 
samleaver
Member
 
Total Posts:  42
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!

 Signature 

Pure - Design. Web. Photography. Video

 
Magento Community Magento Community
Magento Community
Magento Community
 
samleaver
Member
 
Total Posts:  42
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.

 Signature 

Pure - Design. Web. Photography. Video

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

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

 Signature 

Pure - Design. Web. Photography. Video

 
Magento Community Magento Community
Magento Community
Magento Community
 
Siggi_Schmitz
Guru
 
Avatar
Total Posts:  515
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.

 Signature 

Magento Freelancer.

Need an extension? Feel free to contact me!

Web: http://www.sig-tec.de
E-Mail:
Skype: sig-tec
Xing: https://www.xing.com/profile/Siegfried_Schmitz2
Profil auf freelance.de
Profil auf freelancermap.de

 
Magento Community Magento Community
Magento Community
Magento Community
 
samleaver
Member
 
Total Posts:  42
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?

 Signature 

Pure - Design. Web. Photography. Video

 
Magento Community Magento Community
Magento Community
Magento Community
 
Siggi_Schmitz
Guru
 
Avatar
Total Posts:  515
Joined:  2011-07-03
 

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

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

 Signature 

Magento Freelancer.

Need an extension? Feel free to contact me!

Web: http://www.sig-tec.de
E-Mail:
Skype: sig-tec
Xing: https://www.xing.com/profile/Siegfried_Schmitz2
Profil auf freelance.de
Profil auf freelancermap.de

 
Magento Community Magento Community
Magento Community
Magento Community
 
samleaver
Member
 
Total Posts:  42
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>

 Signature 

Pure - Design. Web. Photography. Video

 
Magento Community Magento Community
Magento Community
Magento Community
 
Siggi_Schmitz
Guru
 
Avatar
Total Posts:  515
Joined:  2011-07-03
 

ok, good to know grin

 Signature 

Magento Freelancer.

Need an extension? Feel free to contact me!

Web: http://www.sig-tec.de
E-Mail:
Skype: sig-tec
Xing: https://www.xing.com/profile/Siegfried_Schmitz2
Profil auf freelance.de
Profil auf freelancermap.de

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