Magento2: How to get country list in custom HTML template
-
14-04-2021 - |
Pregunta
I need to display a country list with dropdown in the custom knockout HTML template. Help would be appreciated.
Solución
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.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange