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?
2 Answers 2
I'm not sure how you can do that in Magento 2, the cleanest way I can think of would be to :
- Create a new theme that uses your current theme as a parent
- Set your second store to use the new theme
- 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– Bartosz Herba2017年11月14日 18:34:44 +00:00Commented Nov 14, 2017 at 18:34
-
What is so bad with an additional x seconds of deployment?Ben Crook– Ben Crook2017年11月15日 09:44:09 +00:00Commented Nov 15, 2017 at 9:44
-
1When 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– Bartosz Herba2017年11月15日 10:18:05 +00:00Commented Nov 15, 2017 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– Ben Crook2017年11月15日 10:34:25 +00:00Commented Nov 15, 2017 at 10:34
-
1It'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– Ben Crook2017年11月15日 10:42:53 +00:00Commented Nov 15, 2017 at 10:42
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– fritzmg2018年05月24日 10:46:13 +00:00Commented May 24, 2018 at 10:46
Explore related questions
See similar questions with these tags.