Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call function of another block Magento

Tags:

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

like image 753
Ankit Agarwal Avatar asked May 01 '13 05:05

Ankit Agarwal


People also ask

How do you call one Phtml file in another Phtml file in magento2?

Re: How to call phtml file in another phtml fileecho $this->getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate("Magestore_Webpos::login. phtml")->toHtml();

How can I call Phtml file in CMS page Magento 2?

Call phtml using block codelogin to magento admin. Open any cms page and write block code in content section. After using the block code phtml file will be called on cms page. If you want to call phtml file on all cms pages then you can create a layout file to achieve this.


2 Answers

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.

like image 193
Mahmood Rehman Avatar answered Oct 01 '22 01:10

Mahmood Rehman


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

like image 21
Hassan Ali Shahzad Avatar answered Oct 01 '22 03:10

Hassan Ali Shahzad