Gaurav Khatri
Gaurav Khatri

Reputation: 1

How to call block class function from phtml file

I have block class

    class GauravKhatri_BestSeller_Block_Index extends Mage_Core_Block_Template
{

public function getBestsellerProducts()
{       
//Here is my code
}
}

I have bestseller.phtml file. I want to get result of that function on phtml file.

Can anyone help me how to do it.

Upvotes: 0

Views: 3906

Answers (2)

Prashant Valanda
Prashant Valanda

Reputation: 480

you can call block in template directly

$bestseller = $this->getLayout()->getBlock('bestSeller/index');
$bestseller->getBestsellerProducts();

Upvotes: 0

Pankaj Pareek
Pankaj Pareek

Reputation: 3836

If this template file "bestseller.phtml" is directly associated with your block. like below example:

<block type="bestSeller/index" name="bestseller" template="bestseller.phtml "/>  

then you can access all the functions of this block class GauravKhatri_BestSeller_Block_Index in associated template using $this. like example:

$this->getBestsellerProducts();

Upvotes: 1

Related Questions