【问题标题】:ModX getResources - Chunks in the tpl are displaying parent's contentModX getResources - tpl 中的块正在显示父级的内容
【发布时间】:2013-11-27 20:16:14
【问题描述】:

我有这个 getResourcesCall

[[!getResources? &tpl=GRTpl&includeContent=1&includeTVs=1&parents=[[*id]]]]

在 GRTpl 我包含[[+content]] 标签,但它们只显示父级的内容,而不是子级的内容。是什么赋予了!?

更新:

我在 GRTpl 中使用 ModX 输出过滤器。所以我有一个单选列表框,它根据选择显示块。这是GRTpl:

[[+tv.section_type:eq=`Type One`:then=`[[$Type One Chunk]]` ]]

[[+tv.section_type:eq=`Type Two`:then=`[[$Type Two Chunk]]` ]]

[[+tv.section_type:eq=`Type Three`:then=`[[$Type Three Chunk]]` ]]

[[+tv.section_type:eq=`Type Four`:then=`[[$Type Four Chunk]]` ]]

【问题讨论】:

    标签: modx getresource


    【解决方案1】:

    所以我找到了解决方案。在 GRTpl 中,我将一个 var 传递到每个块中:

    [[+tv.section_type:eq=`Type One`:then=`[[$Type One Chunk? &content=`[[+content]]` ]]` ]]
    
    [[+tv.section_type:eq=`Type Two`:then=`[[$Type Two Chunk? &content=`[[+content]]` ]]` ]]
    
    [[+tv.section_type:eq=`Type Three`:then=`[[$Type Three Chunk? &content=`[[+content]]` ]]` ]]
    
    [[+tv.section_type:eq=`Type Four`:then=`[[$Type Four Chunk? &content=`[[+content]]` ]]` ]]`
    

    然后在块 [[+content]] 中显示子资源的内容。

    【讨论】:

      【解决方案2】:

      上面使用的方法会导致大量的额外处理和网站速度变慢。

      两种选择:

      1) 阅读 Jason Coward 关于条件的优秀文章。

      基本问题是上面显示的代码即使不满足条件也会被MODX扩展和处理。

      所以代替:

      [[*field:is=0:then=[[!SomeScript]]:else=[[$SomeChunk]]]]

      用途:

      [[[[*field:is=0:then=!SomeScript:else=$SomeChunk]]]]​​

      详情请见http://modx.com/blog/2012/09/14/tags-as-the-result-or-how-conditionals-are-like-mosquitoes/

      2) 要进一步增强,请将 getResources 替换为 pdoResources 并使用其出色的条件模板,这意味着您根本不需要使用条件。

      使用 pdoResources,您可以执行以下操作:

      [[!pdoResources? &includeTVs=section_type &tplCondition=section_type &conditionalTpls=`{"类型一":"类型一块","类型二":"类型二块"} 等等。

      谷歌“modx pdotools”查看文档。

      使用这种方法,我将满载电视的 getResources 调用的速度提高了大约 8 倍。

      http://forums.modx.com/thread/90995/performance-question-with-getresources

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-11-11
        • 2019-07-30
        • 2014-02-12
        • 1970-01-01
        • 2015-07-06
        • 1970-01-01
        • 2016-06-13
        • 2016-01-16
        相关资源
        最近更新 更多