1

I have a Magento 2.1.x installation with two store views. I would like to show a particular block in the footer only for one store view.

In Magento 1.9.x I would have done it in this way:

<STORE_storecode>
    <reference name="lorem_ipsum">
        <block type="..." />
    </reference>
</STORE_storecode>

How can I achieve that in Magento 2?

0

I'm not sure how you can do that in Magento 2, the cleanest way I can think of would be to :

  1. Create a new theme that uses your current theme as a parent
  2. Set your second store to use the new theme
  3. Extend the layout XML in your new theme with your change

You'll end up with the same effect, although it is more work than the method you mentioned for Magento 1.

  • Creating additional theme which results in greater compilation time in production mode while deploying version is a very bad idea. – Bartosz Herba Nov 14 '17 at 18:34
  • What is so bad with an additional x seconds of deployment? – Ben Crook Nov 15 '17 at 9:44
  • 1
    When time means money and every second of maintenance generates debt, where bad solutions like your stacks - it can lead to many problems. It doesn't matter in small scale (however bad solution is a bad solution). Also, depending o theme it can be far more than seconds plus there are still magento bugs eg. with generating translations which may result in repeated deployment. And finally, i will not understand why I would like to create additional theme for something that can be done with one if? – Bartosz Herba Nov 15 '17 at 10:18
  • If I was aware of that method I would have added it, but I wasn't aware hence I say "the cleanest way I can think of" and not "the cleanest way is". – Ben Crook Nov 15 '17 at 10:34
  • 1
    It's no problem, you have a very good point and your answer sounds like the better option. I'm a front-end developer so I don't work with deployments too much hence my answer isn't great. It's the joys of stack exchange, you get a wide variety of answers. – Ben Crook Nov 15 '17 at 10:42
0

Instead of doing it in layout xml which is not possible in M2 you can either override/plugin toHtml method in block and implement required logic or add such a logic as separate method in block to call in if/else structure inside of phtml file.

  • Hm, how exactly can you override the block class of an existing block? – fritzmg May 24 '18 at 10:46

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.