2

I am trying to add a custom block to just the homepage. All pages use the same template which is 1column.phtml

In this file I have added a customblock above the content:

<?php echo $this->getChildHtml('customblock') ?>
<?php echo $this->getChildHtml('content') ?>

In my layout.xml within here (I'm guessing this is the hompage?):

<cms_index_index translate="label">

I have added this:

<reference name="notsurethisshouldbe">
  <block type="core/template" name="customblock" template="homepage/customblock.phtml" />
</reference>

In template/homepage/customblock.phtml I have a simple page:

<?php
  echo "testing testing 123";
?>

However nothing is showing up. What have I done wrong?

Thanks

2

Not the correct way. As you mentioned Just on home page you need static block

Just put below any one line code in content of your home page inside Admin->CMS pages

{{block type="cms/block" block_id="home_page_identifier"}} /**Add your home page identifier here***/

or

{{block type="cms/block" block_id="4"}} /**Add your home page id here***/

or

Add below code in layout update XML in CMS page

<block type="cms/block" name="home_block_custom" before="-">
  <action method="setBlockId"><block_id>home_page_identifier</block_id>    </action>
</block> 
0

If you know your block needs to be at the top of the content you could add it to the content block, and as this is a structural block it will automatically render the template.

<reference name="content">
  <block type="core/template" name="customblock" template="homepage/customblock.phtml" />
</reference>

If it needs to be outside content then do the following:

<reference name="customblock">
  <block type="core/template" name="customblock" template="homepage/customblock.phtml" />
</reference>

Also to be consistent with Magento's naming method I recommend custom.block instead of customblock.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.