tags:

views:

94

answers:

1

Hi,

Ok so Ive created static blocks in my CMS area, and Im trying to output them inside of a custom homepage template Ive built.

Every document I can find says to output the block as follows

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

That didnt work for me, so then I tried another way. --

       <?php $block = Mage::getSingleton('core/layout')->createBlock('cms/block')->setBlockId('my-block-identifier');
        echo $block->toHtml();

All the sites referencing this tell me to use the actual blocks identifier to get the block. So then I decide to manually lookup the block_id in my cms_block table and see if using the block_id number in place of the literal my-block-identifier name will work - and it did. So I am confused... Can anyone tell me how I can get the block by the actual identifier, or look up the blocks id by the identifier so that I can grab the block by block name?

Any help much appreciated.

A: 

In the admin, when you are editing the contents of the static block, you will see a field called Identifier second from the top. Copy the value of that field, and insert it into your code. So if your Block is called contact-info in the admin, then your code will look like:

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

The value in that Identifier textbox in the admin is also what will be saved into the cms_block table, as you're worked out.

HTH, JD

Jonathan Day
Right, thats what I did already as I posted above. The problem is, setBlockId is not working as intended for me, it will only reference the block by the manually looked up block_id field, not the named block in the admin section. I think it has to do with the fact that I am first referencing a Block in the homepage cms page, e.g. {{block type="core/template" template="homepage/home.phtml"}} - then in that .phtml im calling the sub block. So basically I am looking for a workaround to look up the block_id by the "identifier" (the name)
thrice801