1

I am using this code to display a block on my home page, I opted to add it via the onecolumn.phtml file because when I added it as a widget via the cms method it would not allow for correct placement and full width without messing a bunch of other related stuff up.

However now it displays on all static cms pages ie about us etc.

Is there some kind of way to check and only display on home page ?

heres my snippet

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

farther down the page i use this one and it only shows up on home page?

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

heres the complete code

<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php
/**
 * Template for Mage_Page_Block_Html
 */
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->getLang() ?>" lang="<?php echo $this->getLang() ?>">
<head>
<?php echo $this->getChildHtml('head') ?>
</head>
<body<?php echo $this->getBodyClass()?' class="'.$this->getBodyClass().'"':'' ?>>
<?php echo $this->getChildHtml('after_body_start') ?>
<div class="wrapper <?php echo $this->getLang().'-lang-class';?>">
    <?php echo $this->getChildHtml('global_notices') ?>
    <div class="page">
        <?php echo $this->getChildHtml('header') ?>

        <div class="main-container col1-layout">
            <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('threeblock1')->toHtml(); ?>
            <div class="container">
                <div class="row">
                    <div class="span12">
                        <div class="main">
                            <?php echo $this->getChildHtml('breadcrumbs') ?>



                                <div class="col-main">
                                    <div class="padding-s">
                                        <?php echo $this->getChildHtml('global_messages') ?>

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

                                        <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('product-categories')->toHtml(); ?>
                                            <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('brands')->toHtml(); ?>
                                    </div>
                                </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <?php echo $this->getChildHtml('footer') ?>
        <?php echo $this->getChildHtml('before_body_end') ?>
    </div>
</div>
<?php echo $this->getAbsoluteFooter() ?>
</body>
</html>
2

To display the block only on the homepage you can replace your code with:

<?php if ($this->getUrl('') == $this->getUrl('*/*/*', array('_current'=>true, '_use_rewrite'=>true))): ?>
    <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('threeblock1')->toHtml(); ?> 
<?php endif; ?>
| improve this answer | |

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.