14

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

4 Answers 4

37

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.

2
  • I tried this. $tabLinks = Mage::app()->getLayout()->getBlockSingleton('Mage_Customer_Block_Account_Navigation'); $allLinks = $tabLinks->getLinks(); but return empty array. Any help?? Commented Dec 16, 2014 at 11:50
  • 'getBlockSingleton()' is not working, 'createBlock()' is working..I don't know why.
    – SIBHI S
    Commented Dec 23, 2015 at 11:10
4

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

2

You can reference using a layout XML file.

for example:

<block type="{Here you can add reference}" name="contactForm" template="contacts/form.phtml"/>
1
  • I didnt get you Actually what i want to do is to change the location of contact Us ..now i have hide the contact us from link.phtml..and also i have created new phtml ..but when i am doing this->getLinks() ..to get all the URL values i am getting NULL over there Commented May 1, 2013 at 9:15
2

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();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.