문제

I have used this link's code to enable currency switcher in the header. But I want to use only this code:

<?php if($this->getCurrencyCount() > 1): ?>
<div class="form-language">
    <label for="custom-currency-selector"><?php echo $this->__('Your Currency:') ?></label>
    <select onchange="window.location.href=this.value" name="custom-currency-selector" id="custom-currency-selector">
        <?php foreach ($this->getCurrencies() as $_code => $_name): ?>
        <option value="<?php echo $this->getSwitchCurrencyUrl($_code)?>"
            <?php if($_code == $this->getCurrentCurrencyCode()): ?>
                selected="SELECTED"
            <?php endif; ?>>
            <?php echo $_code ?>
        </option>
        <?php endforeach; ?>
    </select>
</div>
<?php endif; ?> 

directly in the header without using XML. So what should I write in place of $this->?

도움이 되었습니까?

해결책

Try this code...

<?php 
$currencyBlock = Mage::app()->getLayout()->createBlock('directory/currency');
if($currencyBlock->getCurrencyCount() > 1): ?>
<div class="form-language">
    <label for="custom-currency-selector"><?php echo $this->__('Your Currency:') ?></label>
    <select onchange="window.location.href=this.value" name="custom-currency-selector" id="custom-currency-selector">
        <?php foreach ($currencyBlock->getCurrencies() as $_code => $_name): ?>
        <option value="<?php echo $currencyBlock->getSwitchCurrencyUrl($_code)?>"
            <?php if($_code == $currencyBlock->getCurrentCurrencyCode()): ?>
                selected="SELECTED"
            <?php endif; ?>>
            <?php echo $_code ?>
        </option>
        <?php endforeach; ?>
    </select>
</div>
<?php endif; ?> 

if you don't want to use currency code in header.phtml and want to manage in separate phtml file then you can use below code in header.phtml:

 <?php echo  $this->getLayout()->createBlock('directory/currency')->setTemplate('directory/currency.phtml')->toHtml();?>

you can find phtml file here: app/design/frontend/[Current_Package]/[Current_Theme]/template/directory/currency.phtml

if you still not able to find you can see currency.phtml in here : app/design/frontend/base/default/template/directory/currency.phtml

Hope this helps you. All the best!

다른 팁

poles

try below add then code is header.phtml file

   <?php echo  $this->getLayout()->createBlock('directory/currency')->setTemplate('directory/currency.phtml')->toHtml();?>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top