Magento 1.9 – Add Country Flag Image to Language Switcher Without Extension

languagemagento-1.9store-view

I'am new to Magento and using 1.9.3.1.
Found solution about placing flag image as language switcher(onclick) in

app/design/frontend/package_folder/theme_folder/template/page/switch/languages.phtml

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();?>"><img src="<?php echo $this->getSkinUrl('images/flags/' . $_lang->getCode() . '.png');?>" alt=""></a>
        <?php endif;?>
    <?php endforeach;?>
    </div>
</div>
<?php endif;?>

As you can see, ther is no <select></select> tag.

Here is default template languages.phtml with <select></select>tag

<?php if(count($this->getStores())>1): ?>
<div class="form-language">
    <!-- Code to render flag image -->
    <select id="select-language" title="<?php echo $this->__('Language') ?>" onchange="window.location.href=this.value">
    <?php foreach ($this->getStores() as $_lang): ?>
        <?php $_selected = ($_lang->getId() == $this->getCurrentStoreId()) ? ' selected="selected"' : '' ?>
        <option value="<?php echo $_lang->getCurrentUrl() ?>"<?php echo $_selected ?>><?php echo $this->escapeHtml($_lang->getName()) ?></option>
    <?php endforeach; ?>
    </select>
</div>
<?php endif; ?>

I need to place code to render picture, and to be right betore <select></select> tag depends of store view (but not to be clickable to switch language as first block of code above), and when i chose language in <select></select> tag (to switch language), then flag of another country must be displayed depends of language.

Best Answer

Solution:

<?php if(count($this->getStores())>1): ?>
<div class="form-language">
    <div class="flag-wrapper">
        <?php foreach ($this->getStores() as $_lang): ?>
            <?php if($_lang->getId() == $this->getCurrentStoreId()): ?>
                <img src="<?php echo $this->getSkinUrl('images/flags/' . $_lang->getCode() . '.png');?>" alt="<?php echo $this->htmlEscape($_lang->getName()) ?>">
            <?php endif; ?>
        <?php endforeach ?>
    </div>
    <select id="select-language" title="<?php echo $this->__('Language') ?>" onchange="window.location.href=this.value">
    <?php foreach ($this->getStores() as $_lang): ?>
        <?php $_selected = ($_lang->getId() == $this->getCurrentStoreId()) ? ' selected="selected"' : '' ?>
        <option value="<?php echo $_lang->getCurrentUrl() ?>"<?php echo $_selected ?>><?php echo $this->escapeHtml($_lang->getName()) ?></option>
    <?php endforeach; ?>
    </select>
</div>
<?php endif; ?>
Related Topic