Magento – show currency dropdown on top header links

currency

i want to show currency drop down before my account in top links.
i added below code in links.phtml but nothing shows.

<?php if($this->getCurrencyCount()>1): ?>
<div class="block block-currency">
    <div class="block-content">
        <select name="currency" onchange="setLocation(this.value)">
        <?php foreach ($this->getCurrencies() as $_code => $_name): ?>
            <option>
                <a href="<?php echo $this->getSwitchCurrencyUrl($_code) ?>" title="<?php echo $_code ?>" <?php if($_code==$this->getCurrentCurrencyCode()): ?> class="selected"<?php endif; ?>>
                    <?php echo Mage::app()->getLocale()->currency($_code)->getSymbol()?>
                </a>
            </option>
        <?php endforeach; ?>
        </select>
    </div>
    <div class="block-title-currency">
        <strong><span><?php echo $this->__('Currencies') ?></span></strong>
    </div>
</div>
<?php endif; ?>

Best Answer

You need to add currency dropdown as child block of toplink using layout xml code.

Create local.xml at app/design/frontend/your package/your template//layout/

<?xml version="1.0"?>
<layout version="0.1.0">
    <default>
        <reference name="top.links">
            <block type="directory/currency" name="currencytop"  template="directory/currency.phtml"/>
        </reference>
    </default>
</layout>

Create a new template file topcurrency.phtml at app/design/frontend/your package/your template/template/directory and your code.

<?php if($this->getCurrencyCount()>1): ?>
<div class="block block-currency">
    <div class="block-content">
        <select name="currency" onchange="setLocation(this.value)">
        <?php foreach ($this->getCurrencies() as $_code => $_name): ?>
            <option>
                <a href="<?php echo $this->getSwitchCurrencyUrl($_code) ?>" title="<?php echo $_code ?>" <?php if($_code==$this->getCurrentCurrencyCode()): ?> class="selected"<?php endif; ?>>
                    <?php echo Mage::app()->getLocale()->currency($_code)->getSymbol()?>
                </a>
            </option>
        <?php endforeach; ?>
        </select>
    </div>
    <div class="block-title-currency">
        <strong><span><?php echo $this->__('Currencies') ?></span></strong>
    </div>
</div>
<?php endif; ?>

then in links.phtml call this template file as child block using below code:

<?php echo $this->getChildHtml('currencytop');?>
Related Topic