• Eyelash / php jquery image management
  • Magento CMS : 2 methods for static blocks

    Magento’s backoffice comes with a fairly simple CMS that can do a lot : single pages can be modified (content and layout) via the CMS / Manage Pages menu, and page parts can be shared and modified via the CMS / Static Block menu. Web developers who get a first sight inside templates might find it difficult to integrate a newly created block : we describe here two methods to integrate a block in your magento website.

    How to create a CMS block : Go to Magento admin uder CMS -> Static Blocks and Add New Block. Insert Block Title, Identifier (for example: mycompany-newsblock), set Status to Enabled, insert block Content and Save Block.

    How to add the CMS block to pages (exemple on the right column). You can choose one of these 2 methods

    1. LAYOUT block  modification: in layout/page.xml , find the default / right column block
      <block type=”core/text_list” name=”right” as=”right” />

      and transform it by incorporating the newly created CMS block  :
      <block type=”core/text_list” name=”right” as=”right”>
      <block type=”cms/block” name=”ruedesiam.marge” as=”ruedesiam.marge” after=”-”>
      <action method=”setBlockId”><block_id>mycompany-newsblock</block_id></action>
      </block>
      </block>
    2. Template block addition : add the following code to
      app/design/frontend/YOURTEMPLATE/default/template/callouts/right_col.phtml

      <?= $this->getLayout()->createBlock(‘cms/block’)->setBlockId(‘mycompany-newsblock’)->toHtml() ?>

    The solutionbelow explains how to add a template block : everything here is done via HTML files. (example for theleft column)

    1. in layout/page.xml or in your page custom design, add the following code

    <reference name=”left”>
    <block type=”core/template” name=”productbrand” alias=”productbrand” as=”productbrand” template=”catalog/product/brand.phtml”  />
    </reference>

    2. in template/callouts/ left_col.phtml, add the following :

    <? $this->getChildHtml(‘productbrand’) ?>

    Note : you can avoid xml configuration by creating the core template directly within the phtml :

     <?php  echo $this->getLayout()->createBlock('core/template')->setTemplate('callouts/rassure.phtml')->toHtml() ?>

    <?php  echo $this->getLayout()->createBlock(‘core/template’)->setTemplate(‘callouts/rassure.phtml’)->toHtml() ?>

    1. 4 Responses to “Magento CMS : 2 methods for static blocks”

    2. March 26, 2009 - justin

      thank you,it’s very helpful.

    3. May 22, 2009 - x4hai

      I use Free CMS module, it’s very useful. You can see the demo here: http://demo.hello-magento.com/freecms/furniture.html

    4. June 2, 2009 - Tim

      Hi,
      …not sure if this is in the right area or you can help but I am having trouble adding a static block in a newsletter template. I have tried adding {{block type=”cms/block” block_id=”block-id”}} in the template but on preview it interprets this as a string and the static block does not appear. No response from the Forum. Any ideas? Thanks.
      Tim.
      (www.mytex.co.uk – mobile computing office bundles)

    5. August 8, 2010 - Jeff

      Anyone who’s thinking about using magento should have their head examined; magento is bloated, confusing and bullocks. I’d only suggest using it if you’ve got a penchant for punishment, or 6 months to learn all their “simple” coding conventions … But don’t expect to do this by reading their documentation, or searching for help on their forums; the information you’ll find that way is lacking to say the least. You’ll only learn it by wading through the 5,000 files it installs on your server; you read that write, the standard install contains nearly 5,000 files. I stamp magento with an AVOID AT ALL COSTS label. Future users beware!

    Quick contact form