【问题标题】:How to add a new variable to a viewhelper (Typo3 9)如何将新变量添加到 viewhelper (Typo3 9)
【发布时间】:2018-09-07 09:53:27
【问题描述】:

我创建了自己的 viewhelper 来获取带有 UID 的图像的所有信息。 如果我在 viewhelper 中打印数组,我会得到所有信息,但我无法使用所有这些信息创建一个新的 Fluid 变量,以便在模板中使用。

我尝试使用以下方法创建新变量:

$this->view->assign('sliderItems', $sliderItems);

但我收到“在 null 上调用成员函数 assign()”。

我用以下方式渲染图像:

public function render() {
    /* MY RENDER STUFF */

然后我将提交数组:

    $this->view->assign('sliderItems', $sliderItems);
}

我该如何解决这个问题,以获取流体访问权限?

【问题讨论】:

    标签: typo3 fluid extbase typo3-9.x


    【解决方案1】:

    您可以为此使用 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-22
      • 2019-09-13
      • 1970-01-01
      相关资源
      最近更新 更多