Magento2: How to get country list in custom HTML template
-
14-04-2021 - |
Question
I need to display a country list with dropdown in the custom knockout HTML template. Help would be appreciated.
Solution
With reference to this answer.
Magento already provide some inbuilt solution for this.
<?php $countryBlock = $block->getLayout()->createBlock('Magento\Directory\Block\Data');?>
<?= $countryBlock->getCountryHtmlSelect($defValue = null, $name = 'country_id', $id = 'country', $title = 'Country');?>
You can set default $defValue,$name,$id
as per as your wise.
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange