我创建了自己的viewhelper,用于获取具有UID的图像的所有信息。如果我在viewhelper中打印数组,但是我无法创建包含所有这些信息的新Fluid变量,那么我将获得所有信息,以便在模板中使用。
我尝试用以下方法创建新变量:
$this->view->assign('sliderItems', $sliderItems);
但是我收到“在null上调用成员函数assign()”。
我渲染图像:
public function render() {
/* MY RENDER STUFF */
然后我将提交数组:
$this->view->assign('sliderItems', $sliderItems);
}
如何解决这个问题,以获得流体访问?
您可以使用templateVariableContainer:
$this->templateVariableContainer->add('key', 'value');
如果在循环中使用viewhelper,则必须在渲染后删除变量:
$this->templateVariableContainer->add('key', 'value');
$output = $this->renderChildren();
$this->templateVariableContainer->remove('key');
return $output;
如果在模板中使用viewhelper,则变量将在流体模板中可用。
<vendor:viewhelper>
{key}
</vendor:viewhelper>