rramiii rramiii - 9 months ago 43
PHP Question

how to call block method from magento 1 template

I'm new to magento and always have issues.

For now, I managed to add subscribe popup message and want to add a child block to my main block.

Code:(my custom module is


<reference name="before_body_end">
<block type="newsletter/subscribe" name="newsletter_popup" as="newsletter_popup" template="popup/subscribe.phtml">
<block type="Module/popup_newsletter" name="newsletter11" />
</reference name="before_body_end">

and in
I try the following:


but the result is:


I tried to load the block from template in this way also:


but the result is

what I want to do is call a method from child block (
) and this out put some text, this block for now has these two methods:

puplic function test(){
return 'this is test';

public function _toHtml()
return test();

I can't see were is my mistake.

Can any one help me thankfully, I don't know if you need more code to post. Just let me know if you need

Thanks in advance.

config.xml file:

<?xml version="1.0" encoding="UTF-8"?>


Answer Source

To create object for block in template (phmtl) file. Try the following code

$customBlock = $this->getLayout()->getBlock('block_name'); // You can use newsletter11 in that block_name

To call block function

echo $customBlock->test();