ND17
ND17

Reputation: 208

Pass a variable to a template .phtml block in Magento

This code is write in market.phtml

<?php echo $this->getLayout()->createBlock('core/template')->setData('vendorId',$vendor->getCustomerId())->setTemplate('marketplace/vendors/badge.phtml')->toHtml();?>

In Badge.php

echo $this->vendorId;

But my output is null. Is this correct way to pass data to block?

Upvotes: 2

Views: 5329

Answers (1)

You need to change your variable like this and check it

<?php echo $this->getLayout()->createBlock('core/template')->setVendorId($vendor->getCustomerId())->setTemplate('marketplace/vendors/badge.phtml')->toHtml();?>

Now you can access this vendor ID variable in badge.phtml file like this :

<?php echo $this->getVendorId();?>

Upvotes: 7

Related Questions