gpt4 book ai didi

magento - 将变量传递给 Magento 中的模板 .phtml block

转载 作者:行者123 更新时间:2023-12-02 10:19:15 25 4
gpt4 key购买 nike

这段代码写在market.phtml中

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

在 Badge.php 中

echo $this->vendorId;

但是我的输出为空。这是将数据传递给 block 的正确方法吗?

最佳答案

您需要像这样更改变量并检查它

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

现在您可以像这样访问badge.phtml 文件中的供应商ID 变量:

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

关于magento - 将变量传递给 Magento 中的模板 .phtml block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28832906/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com