kaYko
kaYko

Reputation: 257

Add custom class to wishlist top link

I'd like to add a custom class to the wishlist link for styling.

I tried changing wishlist.xml to this :

<reference name="top.links">

        <block type="wishlist/links" name="wishlist_link" />
        <action method="addLinkBlock"><blockName>wishlist_link</blockName><prepare/><liParams>class="test"</liParams><position>10</position></action>
    </reference>

but the class is not set

I also tried changing code/core/Mage/Wishlist/Block/Links.php to this :

protected function _toHtml()
{
    if ($this->helper('wishlist')->isAllow()) {
        $text = $this->_createLabel($this->_getItemCount());
        $this->_label = $text;
        $this->_title = $text;
        $this->_aParams = 'class="test"';
        $this->_url = $this->getUrl('wishlist');
        return parent::_toHtml();
    }
    return '';
}

but the class it still not set.

Here is my links.phtml file :

<?php $_links = $this->getLinks(); ?>
<?php if(count($_links)>0): ?>
<ul class="links"<?php if($this->getName()): ?> id="<?php echo $this->getName() ?>"<?php endif;?>>
<?php $i=0; ?>
<?php foreach($_links as $_link): ?>
    <?php if ($_link instanceof Mage_Core_Block_Abstract):?>
        <?php echo $_link->toHtml() ;?>
    <?php else: ?>
        <?php $i++; ?>
        <li class="<?php if($_link->getIsFirst()): ?>first<?php elseif($_link->getIsLast()): ?>last<?php else: ?>menu<?=$i?><?php endif; ?>" <?php echo $_link->getLiParams() ?>><?php echo $_link->getBeforeText() ?><a href="<?php echo $_link->getUrl() ?>" title="<?php echo $_link->getTitle() ?>" <?php echo $_link->getAParams() ?>><?php echo $_link->getLabel() ?></a><?php echo $_link->getAfterText() ?></li>
    <?php endif;?>
<?php endforeach; ?>

In result, wishlist is the only top link with no class.

Upvotes: 2

Views: 1449

Answers (1)

Jona
Jona

Reputation: 1156

Interesting, ok never tested this but it don't cost a lot to try it ;)

In your layout file:

<reference name="wishlist_link">
    <action method="setAParams">
        <param><![CDATA[class="myclass"]]></param>
    </action>
</reference>

Upvotes: 4

Related Questions