1

I have created a module where I can add images in the admin and then they will be displayed in the front-end in the form of a banner slider.

all of my admin stuff is working fine it adds images etc etc, so I created a block (/app/code/local/Nublue/Slidemanager/Block/bannerslider.php) which consists of the following:

public function CreateSliderHtml()
{
    $html = '';
    $slideimage = Mage::getModel('nublue_slidemanager/slideimage');
    foreach ($slideimage as $slide) {
        $image = $slide->getImage();
        if ($slide->getUrl() != null || '') {
            $url = $slide->getUrl();
        }
    $html .= '<li><img src="'$image'" href="' if (isset($url)){'$url"'} 'width="600" height="400" alt=""></li>'
    }
    return $html;
}

}

and my class is called 'Nublue_Slidemanager_Block_bannerslider' and it extends 'Mage_Core_Block_Template'

in my template file

(app/design/frontend/base/default/template/Nublue_Slidemanager/bannerslider.phtml)

I have this:

            <!-- Carousel -->
            <div class="jcarousel">
                <ul>
                    <?php echo $this->CreateSliderHtml(); ?>
                </ul>
            </div>

but the echo $this->CreateSliderHtml(); gives an error

Invalid method Mage_Core_Block_Template::CreateSliderHtml(Array ( ) )

and I know the template file is being called because if I remove the php code from the template and hardcode some images then they show up.

Is there an xml file I need to edit somewhere? I thought as long as I defined where I was getting blocks and helpers and things from it would work. So to clarify I do have Nublue_Slidemanager.xml and config.xml in their correct folders

1
  • you need to define block in layout file as child in order to use that function in template file. Commented Jan 12, 2016 at 11:05

1 Answer 1

2
  1. The class name must be Nublue_Slidemanager_Block_Bannerslider with capital B (also change the file name)
  2. Your config.xml must define a class alias prefix for your blocks, for example:

    <global>
        <blocks>
            <slidemanager>
                <class>Nublue_Slidemanager</class>
            </slidemanager>
        </blocks>
    </global>
    
  3. Wherever you integrate the block (CMS or Layout XML), you need to specify the type (i.e. the class alias):

    • CMS:

      {{block type="slidemanager/bannerslider" template="Nublue_Slidemanager/bannerslider.phtml"}}
      
    • Layout XML:

      <block name="bannerslider" type="slidemanager/bannerslider" template="Nublue_Slidemanager/bannerslider.phtml" />
      

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.