我已使用此link's代码在标头中启用货币切换器。但我想只使用这段代码:
<?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; ?>
直接在标题中而不使用XML。那么我该怎么写代替$this->
?
答案 0 :(得分:1)
试试这段代码......
<?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; ?>
如果您不想在header.phtml中使用货币代码并希望在单独的phtml文件中管理,那么您可以在header.phtml中使用以下代码:
<?php echo $this->getLayout()->createBlock('directory/currency')->setTemplate('directory/currency.phtml')->toHtml();?>
你可以在这里找到phtml文件:app/design/frontend/[Current_Package]/[Current_Theme]/template/directory/currency.phtml
如果你仍然无法找到,你可以在这里看到currency.phtml:app/design/frontend/base/default/template/directory/currency.phtml
希望这会对你有所帮助。一切顺利!
答案 1 :(得分:1)
极点
尝试以下 添加然后代码是header.phtml文件
<?php echo $this->getLayout()->createBlock('directory/currency')->setTemplate('directory/currency.phtml')->toHtml();?>