1

In the content of a cms page I add a (non cms) block

{{block type="A/B" template="xxx/xxx.phtml"}}

If cms page is set as home page is ok

If is not set as home page is not appearing

Obviously I miss something but what ?Any ideas ?

Myslider.php

class Mytheme_Myslider_Block_Myslider extends Mage_Core_Block_Template
{
    public function _prepareLayout()
    {
        return parent::_prepareLayout();
    }

    public function getDataSlides()
    {
        $data_slides  = Mage::getModel('Myslider/Myslider')->getCollection()
            ->addFieldToSelect('*')
            ->addFieldToFilter('status', 1);

        $data=$data_slides->toArray();
        $filtered_data=array();
        if(count($data['items']))
        foreach($data['items'] as $slide)
        {
            $stores=explode(',',$slide['store_id']);
            if(in_array(Mage::app()->getStore()->getStoreId(),$stores) || in_array(0,$stores))$filtered_data[]=$slide;
        }

        return $filtered_data;
    }

    public function getDataSlider()
    {
        if (!$this->hasData('Myslider'))$this->setData('Myslider', Mage::registry('Myslider'));
        else return $this->getData('Myslider');

    }

}

myslider.phtml

<div id="slider_top">

<ul class="rslides" id="carousel1">

    <?php
    $slides = $this->getDataSlides();
    foreach($slides as $slide)
    {
    ?>

         <li>
          <div class="overlap_widget_wrapper">
            <div class="left_image">
              <div class="placeholder"><a href="<?php echo $slide['link'];?>"><img src="<?php echo Mage::getBaseUrl('media') . $slide['image'];?>" alt="" /></a></div>
            </div>
            <div class="right_image">
              <div class="placeholder"><a href="<?php echo $slide['link_1'];?>"><img src="<?php echo Mage::getBaseUrl('media') . $slide['image1'];?>" alt="" /></a></div>
            </div>
            <div class="clear"></div>
          </div>
        </li>

    <?php } ?>

</ul>

4
  • can you shod the content of the block class and/or template ?
    – Marius
    Commented Aug 13, 2015 at 12:16
  • you want all page right?
    – Magento 2
    Commented Aug 13, 2015 at 12:17
  • do you want that block for all cms pages? Commented Aug 13, 2015 at 12:18
  • I added both php and phtml @Marius Commented Aug 13, 2015 at 16:34

1 Answer 1

2

If you want to add a block to all CMS page.

Use the below code in your local.xml file or in your module layout file.

<cms_page>
    <reference name="content">
        <block type="A/B" name="your.unique.name" template="xxx/xxx.phtml"/>
    </reference>
</cms_page>

Or if you want to add only for home page use

cms_index_index handle(replace cms_page with cms_index_index) in above code

2
  • This is a much cleaner solution than using those ugly tags/variables as mentioned in the start post.
    – Roy
    Commented Aug 13, 2015 at 13:12
  • This is what I have done in first place in cms.xml but the problem remains. I placed it in local.xml and is not solved. This looks strange Is there a way to enable or disable a module per page to look if this is the problem ? Commented Aug 13, 2015 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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