L
L
lagudal2020-03-04 12:20:19
Magento
lagudal, 2020-03-04 12:20:19

How to display icons (flags) for all stores except the current one?

It is necessary to replace the standard dropdown switcher with flags in the standard M2 language switcher.
Found the code, everything works as it should.
But it is also necessary not to show the flag of the current store, i.e. it is necessary to show everything except where the user is located.
Of course, you can just hide it with css, but it seems to me that php would be more correct.
Here is the code, plz tell me where to add the condition.

<?php
/**
 * Language switcher template
 */
if (count($this->getStores())) { ?>
<div class="langs-wrapper">
    <?php foreach ($this->getStores() as $_lang) { ?>
        <a class="lang-flag" href="#" data-post='<?php echo $block->getTargetStorePostData($_lang); ?>'><img src="<?php echo $this->getViewFileUrl('images/flags/' . $_lang->getCode() . '.png');?>" alt="<?php echo $_lang->getName(); ?>" /></a>
    <?php } ?>
    </div>
<?php
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Belevtsov, 2020-05-31
@denistrator

<?php foreach ($this->getStores() as $_lang) : ?>
    <?php if ($_lang->getId() !== $block->getCurrentStoreId()) : ?>
        ...
    <?php endif; ?>
<?php endforeach; ?>

see Magento_Store::switch/flags.phtml for an example

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question