I want to switch my language menu with flags. I am using Fasony theme. my current code for the language_custom.phtml is :

<?php if (count($block->getStores())>1): ?>
<?php $id = $block->getIdModifier() ? '-' . $block->getIdModifier() : ''?>
<div class="switcher language switcher-language">
    <strong class="label switcher-label hidden"><span><?php /* @escapeNotVerified */ echo __('Language') ?></span></strong>    
    <span class="switcher-title"><?php /* @escapeNotVerified */ echo __('Your Language : ') ?></span>
    <div class="selected">
        <strong class="view-<?php echo $block->escapeHtml($block->getCurrentStoreCode()) ?>">
            <span><?php echo $block->escapeHtml($block->getStoreName()) ?></span>
    <ul class="sub-option">
        <?php foreach ($block->getStores() as $_lang): ?>
            <?php if ($_lang->getId() != $block->getCurrentStoreId()): ?>
                <li class="view-<?php echo $block->escapeHtml($_lang->getCode()); ?> switcher-option">
                    <a href="#" data-post='<?php /* @escapeNotVerified */ echo $block->getTargetStorePostData($_lang); ?>'>
                        <span class="flag-icon flag-icon-<?php echo $_lang->getCode() ?>"></span> <?php echo $block->escapeHtml($_lang->getName()) ?>
                <?php endif; ?>
            <?php endforeach; ?>

<?php endif; ?>

and it looks like this : enter image description here

I changed it with this code :

<?php if(count($this->getStores())>1): ?>
<div class="form-language">
    <div class="langs-wrapper">
    <?php foreach ($this->getStores() as $_lang): ?>
        <?php if ($_lang->getCode() != 'default'): ?>
        <a class="lang-flag" href="<?php echo $this->getCurrentUrl().'?___store='.$_lang->getCode();?>" style="text-decoration:none;" title="<?php echo $_lang->getCode();?>">
            <img src="<?php echo $this->getSkinUrl('images/flags/'.$_lang->getCode().'.gif');?>" alt="<?php echo $_lang->getCode();?>">
        <?php endif;?>
    <?php endforeach;?>
<?php endif;?>

But I can't get the pictures :

enter image description here

in the code inspector I get empty src="":

<a class="lang-flag" href="?___store=english" style="text-decoration:none;" title="english">
    <img src="" alt="english">

I want also to change the icon of the setting with the current language flag.

My flag icons english.png and deutsch.png are in the folder : app/design/frontend/Venustheme/fasony/web/images/flags/


maybe a little late, but I tried your code changing the url image with this and it worked well :

<?= $block->escapeUrl($block->getViewFileUrl('images/flags/flag_' . $_lang->getCode() . '.gif'));?>

as I see you don't use $block but $this, maybe we're not using same version of Magento.

|improve this answer|||||

Fine, just hide the language in the string, replace:

<a class="lang-flag" href="<?php echo $this->getCurrentUrl().'?___store='.$_lang->getCode();?>" style="text-decoration:none;" title="<?php echo $_lang->getCode();?>">


<a href="#" data-post='<?= /* @noEscape */ $block->getTargetStorePostData($_lang) ?>'>
|improve this answer|||||

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.