【问题标题】:Dynamicly change TYPO3 fluid Layout by typeNum通过 typeNum 动态改变 TYPO3 流体布局
【发布时间】:2014-02-24 15:16:43
【问题描述】:

我正在使用扩展流体页面,并希望通过 typeNum 切换布局。 是否可以通过条件更改 f:layout? 这行不通:

<f:layout name="{f:if(condition: '{typeNum} == 666', then: 'PageAjax', else: 'Page')}"/>

【问题讨论】:

    标签: typo3 fluid typo3-6.1.x flux


    【解决方案1】:

    你不能使用 if 语句来代替吗? 恕我直言,这更容易阅读 - 如果您需要添加更多取决于 typeNum 的参数,它将保持可读性。

    <f:if condition="{typeNum} == 666">
      <f:then>
        <f:layout name="PageAjax">
      </f:then>
      <f:else>
        <f:layout name="Page">
      </f:else>
    </f:if>
    

    【讨论】:

    • 我刚刚采用了内联 if 条件。但是,如果我采用基于标签的写作或内联写作并不重要。如果 f:layout 部分中的 viewhelper,我认为我无法访问流体。
    • 这不起作用 - 原因是 f:layout 节点的值在没有实际渲染模板的情况下被处理。
    【解决方案2】:

    我现在已经在布局模板中添加了条件。我从打字稿中得到 typeNum。

    <f:if condition="{f:cObject(typoscriptObjectPath:'plugin.nc_template.settings.pageLayout')} == 'Default'">
    <p>Default Template</p>
    </f:if>
    
    <f:if condition="{f:cObject(typoscriptObjectPath:'plugin.nc_template.settings.pageLayout')} == 'Ajax'">
        <p>Ajax Template</p>
    </f:if>
    

    我在 fedext 页面上找到了一个示例,但无法运行: https://fedext.net/blog/archive.html?tx_news_pi1[news]=55&tx_news_pi1[%40widget_0][currentPage]=8&cHash=f9c3165598a28d2aa98fd30ef115bb75

    【讨论】:

      【解决方案3】:

      建议的方法:

      &lt;f:layout name="Page/{typeNum}"/&gt;

      所需文件:

      • 资源/私人/布局/页面/0.html
      • 资源/私人/布局/页面/666.html

      请注意:这仅在保证 {typeNum} 变量存在时才有效 - 如果不存在,您将面临“找不到模板文件”错误且文件名为空。为避免这种情况,您可以使用 VHS 扩展的 v:var.convert ViewHelper 来确保正确的值:

      &lt;f:layout name="Page/{typeNum -&gt; v:var.convert(type: 'integer')}"/&gt;

      【讨论】:

      • 这并不能解释为什么上述方法不起作用。很高兴知道,以便处理类似的问题。
      【解决方案4】:

      我最近遇到了同样的问题,经过几次研究找到了解决方案。

      问题是,您不能在&lt;f:layout&gt; 中使用&lt;f:if&gt;&lt;f:cObject&gt; 或其他嵌套流体。否则,你会在缓存文件中得到一个致命错误,说call to a member function getViewHelper() on a non-object. 而当你查看缓存文件时,你会发现这是因为$self 没有定义。

      因此,我的解决方案是,在\TYPO3\CMS\Fluid\Core\Compiler\TemplateCompiler 中搜索public function getLayoutName(,并在\$currentVariableContainer = \$renderingContext-&gt;getTemplateVariableContainer(); 之前添加\$self = \$this;,就像generateCodeForSection() 一样

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-07-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-04-05
        • 1970-01-01
        • 2017-07-14
        • 1970-01-01
        相关资源
        最近更新 更多