2

I have a custom module and created a block handle in my configuration file as below

    <blocks>
        <onestepcheckout>
            <class>Ucs_OneStepCheckout_Block</class>
        </onestepcheckout>
        .
        .
        .
    </blocks>

Then created a block file inside app/code/local/ucs/OneStepCheckout as below

<?php
class Ucs_OneStepCheckout_Block_Review extends Mage_Core_Block_Template
{
    public function getReviewTemplate()
    {
        return 'Success';
    }

}

Then trying to create the getReviewTemplate from theme/checkout/onepage.phtml as below

$block=$this->getLayout()->createBlock('onestepcheckout_review')->getReviewTemplate();
                echo '<pre>'; print_r($block);

It throws the error as below

Fatal error: Call to a member function getReviewTemplate() on a non-object

What is the wrong with my code?

3

You block type is wrong should be

createBlock('onestepcheckout_review')

should be

createBlock('onestepcheckout/review')

It logic like :

Block_TYpePrefix/RestOfClassname.

onestepcheckout block type prefix / group name of module Ucs_OneStepCheckout Module as you define at config.xml

<blocks> <onestepcheckout><!-- this is called as block type prefix / group name of module Ucs_OneStepCheckout --> <class>Ucs_OneStepCheckout_Block</class> </onestepcheckout> ....

If you want to call Ucs_OneStepCheckout_Block_Review class as block type then convert like this:

  • Ucs_OneStepCheckout_Block = onestepcheckout

Review = review

Between Block groupName & rest of class name a / should come.

So block type is onestepcheckout/review

1

It's onestepcheckout/review, not onestepcheckout_review (class group alias, slash, snake cased rest of the class name)

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.