You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Typo3-11.5中TypoScript输出inline字段时如何使用tt_content.uid?

解决方案:动态引用tt_content的UID到Repeater查询

问题核心是要在CONTENT对象的查询条件中,动态获取当前tt_content记录的UID,替代硬编码的422。以下是正确的实现方式:

正确的TypoScript写法

修改countries_repeater下的select.where部分,使用TypoScript的字段引用语法{field:uid}来获取当前tt_content的UID:

tt_content.countries {
    fields {
        content {
            fields {

                countries_text1 = TEXT
                countries_text1 {
                    field = countries_text1
                }

                countries_text2 = TEXT
                countries_text2 {
                    field = countries_text2
                }

                countries_repeater = COA
                countries_repeater {
                    10 = CONTENT
                    10 {
                        table = tx_countries_domain_model_repeater
                        select {
                            selectFields = title,country
                            pidInList.field = pid
                            // 关键修改:用{field:uid}动态获取当前tt_content的UID
                            where = parent_table='tt_content' AND parent_uid={field:uid}
                            orderBy = sorting
                        }
                        renderObj = COA
                        renderObj {
                            10 = TEXT
                            10 {
                                field = title
                                htmlSpecialChars = 1
                                wrap = {"title": "|"###BREAK###

                            }
                            20 = TEXT
                            20 {
                                field = country
                                htmlSpecialChars = 1
                                wrap = "country": "|"}###BREAK###
                            }
                        }
                        stdWrap.split {
                            token = ###BREAK###
                            cObjNum = 1 |*|2|*| 3
                            1 {
                                current = 1
                                stdWrap.wrap = [|
                            }
                            2 {
                                current = 1
                                stdWrap.wrap = ,|
                            }
                            3 {
                                current = 1
                                stdWrap.wrap = |]
                            }
                        }
                    }
                }
            }
        }
    }
}

为什么之前的尝试失败?

  • current:uid:current在CONTENT对象的上下文里指向的是当前循环的tx_countries_domain_model_repeater记录,而非父级的tt_content记录,无法获取正确的UID。
  • ###data.uid###:这种标记是TYPO3的Marker语法,仅在模板文件(如Fluid或老的HTML模板)中生效,TypoScript里不支持该写法。

备选方案:用stdWrap构建where条件

如果遇到复杂的条件拼接,可以用stdWrap动态生成where语句,写法如下:

select {
    selectFields = title,country
    pidInList.field = pid
    where.cObject = TEXT
    where.cObject {
        dataWrap = parent_table='tt_content' AND parent_uid={field:uid}
    }
    orderBy = sorting
}

内容的提问来源于stack exchange,提问作者Дмитрий Круговой

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 09:52:53