'How to apply <span> tag to My Cart top link in magento?

I have changed texts My cart to My Shopping Bag in top links through below code.

public function addCartLink()
{
        $parentBlock = $this->getParentBlock();
        if ($parentBlock && Mage::helper('core')->isModuleOutputEnabled('Mage_Checkout')) {
            $count = $this->getSummaryQty() ? $this->getSummaryQty()
                : $this->helper('checkout/cart')->getSummaryCount();
            if ($count == 1) {
                $text = $this->__('My Shopping Bag (%s)', $count);
            } elseif ($count > 0) {
                $text = $this->__('My Shopping Bag (%s)', $count);
            } else {
                $text = $this->__('My Shopping Bag');
            }

            $parentBlock->removeLinkByUrl($this->getUrl('checkout/cart'));
            $parentBlock->addLink($text, 'checkout/cart', $text, true, array(), 50, null, 'class="top-link-cart"');
        }
        return $this;
    }

Now, I want to apply tag to shopping cart quantity. So, It should look like My Shopping Bag 0. 0 (quantity) should be in red color. So what should I do?



Solution 1:[1]

your code is right but in else part its want tricky way. you can show like this $text = $this->__('My Shopping Bag (0)'); may its help you

Thanks Anand

Solution 2:[2]

<span> can be added directly.

public function addCartLink()
{
        $parentBlock = $this->getParentBlock();
        if ($parentBlock && Mage::helper('core')->isModuleOutputEnabled('Mage_Checkout')) {
            $count = $this->getSummaryQty() ? $this->getSummaryQty()
                : $this->helper('checkout/cart')->getSummaryCount();
            if ($count == 1) {
                $text = $this->__('My Shopping Bag <span>(%s)</span>', $count);
            } elseif ($count > 0) {
                $text = $this->__('My Shopping Bag <span>(%s)</span>', $count);
            } else {
                $text = $this->__('My Shopping Bag');
            }

            $parentBlock->removeLinkByUrl($this->getUrl('checkout/cart'));
            $parentBlock->addLink($text, 'checkout/cart', $text, true, array(), 50, null, 'class="top-link-cart"');
        }
        return $this;
    }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Anand Singh
Solution 2 vinzee