1

I am trying to show currency switcher in custom template file.

I referred some links and found for magento1.

Where they used below code in the template files.

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

Same code i tried in magento2, which is not working.

I have tried this also in my template file.

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

Which is not working.

Can anyone help me is there any other way to achieve this functionality.

Thanks!!

  • Good to hear that you have resolved your issue. +1 for anwer acceptance :) – Shoaib Munir Aug 5 at 6:38
1

Try this code instead:

echo $this->getLayout()
            ->createBlock("Magento\Directory\Block\Currency")
            ->setTemplate("Magento_Directory::currency.phtml")
            ->toHtml();

This should work anywhere in any phtml

  • 1
    This worked for me.. Thanks – Manjunath Aug 5 at 6:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.