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

Fabian Schmengler
66.2k25 gold badges191 silver badges422 bronze badges
asked Jan 12, 2016 at 10:09
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" />
      
answered Jan 20, 2016 at 12:03

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.