TYPO3中如何为每个tt_content元素匹配对应tt_address记录
TYPO3 关联tt_content与tt_address数据处理问题
问题背景
在tt_content表新增customer_id字段存储tt_address的uid,需要读取该字段并关联获取对应tt_address记录,在Fluid模板中展示其name和company属性。
初始尝试配置
tt_content.customerdata =< lib.contentElement tt_content.customerdata { templateName = Kundeninfo dataProcessing { 10 = TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor 10 { table = tt_content uidInList.field = customer_uid fieldName = customer_uid ??? as = customer } } }
测试可行配置(固定uid版)
以下配置在指定固定tt_content uid(568)时可正常运行,但无法适配所有内容元素:
10 = TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor 10 { if.isTrue.field = customer_uid table = tt_content selectFields = tt_address.* join = tt_address ON tt_address.uid IN(tt_content.customer_uid) where = tt_content.uid = 568 as = customer }
最终解决方案
要实现每个tt_content元素匹配对应唯一tt_address记录,只需动态绑定当前内容元素的uid,调整配置如下:
10 = TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor 10 { if.isTrue.field = customer_uid table = tt_content selectFields = tt_address.* join = tt_address ON tt_address.uid = tt_content.customer_uid where = tt_content.uid = {field:uid} as = customer insertData = 1 }
核心调整点
- 将
join条件中的IN改为=,因为每个tt_content仅关联单个tt_address,匹配更精准 where使用{field:uid}动态获取当前tt_content的uid,同时必须开启insertData = 1,让TYPO3解析字段变量- 配置生效后,每个带
customer_uid的内容元素都会自动匹配对应的tt_address记录
内容的提问来源于stack exchange,提问作者Steffi
相关产品推荐
相关产品推荐

