【问题标题】:Using a custom ViewHelper in the configuration section在配置部分使用自定义 ViewHelper
【发布时间】:2016-11-02 13:23:28
【问题描述】:

我写了一些 ViewHelper,它们工作得很好,但只在 Main-Section... 为了更好地理解:

<f:section name="Configuration">
  <flux:field.select name="first" label="first" items="{0: '10', 1: '40'}"/>
  <flux:field.select name="second" label="second" items="{myViewHelpers:load()}"/>
</f:section>
<f:section name="Preview">
</f:section>
<f:section name="Main">
  {myViewHelpers:load()}
</f:section>

{myViewHelpers:load()} 返回一个字符串,例如

{0: '10', 1: '40'}

在 Main-Section 中这非常有效,但是如果我在 Configuration-section 中使用相同的 ViewHelper,它就不会再加载后端了...我在 Typo3 中只得到一个空白字段,通常元素出现。

如有任何建议,我将不胜感激!

【问题讨论】:

    标签: typo3 fluid view-helpers viewhelper


    【解决方案1】:

    您的 ViewHelper 返回一个字符串,该字符串反过来被流体解释为一个数组(大括号)。所以流体什么也打印不出来。您确定不需要将该数组传递给另一个 ViewHelper,例如 flux:field.select

    如果你需要从你的 ViewHelper 生成一个可用的数组,你应该使用

    $templateVariableContainer = $renderingContext->getTemplateVariableContainer();
    $templateVariableContainer->add($arguments['myNewVariable'], $array);
    

    然后你可以像往常一样访问你的变量:

    {myNewVariable.0}
    

    【讨论】:

    • 我不确定这是否能解决问题,因为我还有一个选择,将它作为一个数组返回,这也不起作用。我不确定这是否能解决问题,因为我还没有弄清楚的东西完全破坏了我的 ViewHelpers。即使是工作的人最终也会出错。无论如何,非常感谢您的回答。我要结束这个问题,因为我无法测试解决方案......
    猜你喜欢
    • 1970-01-01
    • 2010-10-25
    • 2010-11-12
    • 2013-09-17
    • 2011-07-04
    • 2012-12-12
    • 2013-09-21
    • 1970-01-01
    相关资源
    最近更新 更多