Ankit Agarwal
Ankit Agarwal

Reputation: 124

How to call function of another block Magento

I am trying to change the reference block of contact us link..I created all the phtml file and all.. Now in Phtml file when i am calling

<?php $_links = $this->getLinks(); ?> 

I am getting number of links as 0..because it cant get the object of links.php.. I want to know how can I have reference object of contacts.phtml

Upvotes: 14

Views: 41424

Answers (4)

Hassan Ali Shahzad
Hassan Ali Shahzad

Reputation: 2724

block to block calling

Also try call other block class method from current template block class.

$s = Mage::app()->getLayout()->getBlockSingleton('myproductfamily/family');
        print_r($s->getCollection($collectionId));exit;

where: myproductfamily = ModuleName

family = blockClass

Upvotes: 4

Rakesh
Rakesh

Reputation: 746

Please try with this. There are two syntax to call block method/function as below.

$_blockData = $this->getLayout()->getBlockSingleton('yourmodule/blockname')->getFunctionName();

or

$_blockData = $this->getLayout()->createBlock('yourmodule/blockname')->getFunctionName();

Upvotes: 2

Mahmood Rehman
Mahmood Rehman

Reputation: 4331

Hi you can do it by creating reference to that Block.Like

 $cpBlock = $this->getLayout()->getBlockSingleton('your block class'); //ect Mage_Catalog_Block_Product_List_Toolbar

Than you can easily call every function of that class like $cpBlock->getLinks();.Other way is using XML block code.Add contact us xml reference just like user2338443 mentioned to your custom xml and than access functions of that block.

Upvotes: 37

user2338443
user2338443

Reputation:

You can reference using a layout XML file.

for example:

<block type="{Here you can add reference}" name="contactForm" template="contacts/form.phtml"/>

Upvotes: 2

Related Questions