CMS – How to Create Multilingual Static Block in Magento

blockscmslocalisationstore-view

I need to create multilingual static block. So far I have created static block with id 'delivery_returns'.

I'm calling it in catalog\product\view.phtml like this:

$deliveryBlock = Mage::getModel('cms/block')->load('delivery_returns');
echo $deliveryBlock->getTitle();
echo $deliveryBlock->getContent();

I understand that to translate this block:

  1. I should just create another one.
  2. Choose my desired language from store_view field
  3. and keep the static block identifier same as original.

This method works with 'footer_links' and also with another static block I made, called 'header_links', but apparently it is not working with 'delivery_returns' block.
Changing store language does not load corresponding translated 'delivery_returns' block

What am I missing?
Is there a better way to achieve this?

Best Answer

  1. Create a static block for each language, all with the same identifier.
  2. Render the block with the cms/block block. It will automatically add the store ID to load the correct version of the block.

Here's an easy way to load and render the block directly in the template file:

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('delivery_returns')->toHtml() ?>

Alternatively, declare the block in a layout file and render it with <?php echo $this->getChildHtml('delivery_returns') ?>:

<block type="cms/block" name="product.delivery_returns" as="delivery_returns">
    <action method="setBlockId"><block_id>delivery_returns</block_id></action>
</block>
Related Topic