Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento static CMS block in XML layout with two or more storeviews

I have two static CMS Blocks called "promo_en" and "promo_de" - translated for the two existing storeviews "en" and "de".

I'd like to add them to the sidebar of some modules using the layout.xml files of the modules.

The problem is that if I add them both using the following syntax - they both show disregarding the storeview I'm currently in (I would expect some automatic filtering):

<block type="cms/block" name="Promo_de">
    <action method="setBlockId"><block_id>promo_de</block_id></action>
</block> 
<block type="cms/block" name="Promo_en">
    <action method="setBlockId"><block_id>promo_en</block_id></action>
</block> 

If I rename them both to "promo" and use the following syntax - it works fine until I activate Magento's cache - then the output of the CMS block freezes on whatever storeview is cached first:

<block type="cms/block" name="Promo">
    <action method="setBlockId"><block_id>promo</block_id></action>
</block> 

And ideas or workarounds on the matter are highly appreciated.

like image 688
backyardKiwi Avatar asked Jun 24 '11 15:06

backyardKiwi


People also ask

How do you call CMS block in Magento 2 using Layout XML?

Except for displaying CMS block on CMS Page or CMS Block, showing it on category page there is an option to call CMS block programmatically using XML file. You need to replace "my_cmsblock_identifier" with your CMS block Identifier or ID (we recommend to use Identifier).

What is the correct way to inject CMS block in a layout?

A CMS block is injected into the layout by using the Magento/Cms/Block/Block class with the block_id argument. Any block or container can be used as a reference. As a result, the CMS block added to the bottom of the page.


1 Answers

Why not create the static blocks with same identifier, and then only enable them in corresponding store view?

<block type="cms/block" name="Promo">
    <action method="setBlockId"><block_id>promo</block_id></action>
</block> 

Then create 2 static blocks with identifier promo and only enable them in storeview where they belong?

like image 129
Mikael Desmareth Rasmussen Avatar answered Sep 20 '22 10:09

Mikael Desmareth Rasmussen