简体   繁体   English

将变量传递给Magento中的模板.phtml块

[英]Pass a variable to a template .phtml block in Magento

This code is write in market.phtml 这段代码写在market.phtml中

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

In Badge.php 在Badge.php中

echo $this->vendorId;

But my output is null. 但是我的输出为空。 Is this correct way to pass data to block? 这是传递数据进行阻止的正确方法吗?

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 : 现在,您可以像这样在badge.phtml文件中访问此供应商ID变量:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM