2

What i have tried is the following.

I have a class which extends Mage_Adminhtml_Block_Widget_Form. Inside that i have the _prepareLayout function. Now i have set a block inside that function like this.

echo $this->getLayout()->createBlock('adminhtml/template')->setTemplate('path/tothefile.phtml')->toHtml();

Its working. But the issue is i have a javascript code inside this .phtml file and its running twice.

May be because of the core/text_list block type of widget instance or for the toHtml() . Do you guys have any idea whats wrong.

  • have you specified that block in layout.xml ? – sandip Jan 7 '17 at 7:24
  • Why i should add it inside layout.xml ??...I was trying to add it from block. However i managed to do it. Thanks. – Kingshuk Deb Jan 7 '17 at 8:21
  • @KingshukDeb, how did you add a custom template file for the admin form? – musicliftsme Jan 26 '17 at 0:48
  • 1
    @KingshukDeb $this->getLayout()->createBlock('core/text', 'example-block')->setText('<div id="messages"><ul class="messages"><li class="error-msg"><ul><li><span>CreateBlock.</span></li></ul></li></ul></div>') – sandip Jan 26 '17 at 2:11
1

Add __toHtml() method in form container block.

    protected function _toHtml() {
        $tabsContainer = $this->getLayout()->createBlock('core/text', 'example-block')->setText('<div id="messages"><ul class="messages"><li class="error-msg"><ul><li><span>CreateBlock.</span></li></ul></li></ul></div>');

        return parent::_toHtml() .
                $tabsContainer->toHtml() .
                '<div data id="tabs_container"></div>';
    }

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.