如何在 Typoscript 中获取页面类别(并与 tx_news 一起使用) [英] How to get page categories in Typoscript (and use with tx_news)
问题描述
我想读出一个页面的系统类别以供 tx_news 进一步使用(显示与页面具有相同类别的新闻 - 因为 tx_news 使用系统类别).
I would like to read out a page's system categories for further use with tx_news (to display news that have the same categories as the page - as tx_news is using system categories).
我正在寻找本机解决方案,希望通过 getText,例如:plugin.tx_news.settings.categories.data = page:categories
但这似乎还不存在
I was looking for a native solution, hopefully via getText, something like:
plugin.tx_news.settings.categories.data = page:categories
but that doesn't seem to exist yet
此外,我尝试使用 sys_category_records_mm 来简化查询,其中包含该案例所需的所有信息,但 TYPO3 抱怨$TCA 数组中没有条目":
Also, I tried to simplify the query by using sys_category_records_mm, which contains all the information needed for that case, but TYPO3 complains that "there is no entry in the $TCA array":
lib.categoryUid = CONTENT
lib.categoryUid {
wrap = kategorien:|
table = sys_category_record_mm
select {
selectFields = uid
where = uid_foreign = {TSFE:id}
where.insertData = 1
}
renderObj = TEXT
renderObj {
field = uid
wrap = |,
}
}
这样很好,但这是不允许的.
So that would be nice, but it's not allowed.
推荐答案
这是一个适用于我的设置的解决方案.编辑器为页面选择类别,并获取属于该类别的所有新闻项目.
Here's a solution that works in my setup. The editor chooses categories for the page, and gets all news items that belong to the category.
temp.categoryUid = CONTENT
temp.categoryUid {
table = pages
select {
// dontCheckPid doesn't exist for CONTENT objects, so make it recursive from root page (or pidInList.data = leveluid:-2
pidInList = {$pidRoot}
recursive = 99
selectFields = sys_category.uid as catUid
join = sys_category_record_mm ON pages.uid = sys_category_record_mm.uid_foreign JOIN sys_category ON sys_category.uid = sys_category_record_mm.uid_local
where = sys_category_record_mm.tablenames = 'pages' AND sys_category_record_mm.uid_foreign = {TSFE:id}
where.insertData = 1
// not necessary for this use case
// orderBy = sys_category.sorting
}
renderObj = TEXT
renderObj {
field = catUid
// Hack: if there are no cats selected for a page, all news are displayed
// so I just pass a catUid that's quite unlikely
wrap = 999999,|,
}
}
lib.newstest = USER
lib.newstest {
userFunc = tx_extbase_core_bootstrap->run
extensionName = News
pluginName = Pi1
switchableControllerActions {
News {
1 = list
}
}
settings < plugin.tx_news.settings
settings {
limit = 5
orderBy = datetime
orderDirection = desc
detailPid = {$pidNachrichtenDetail}
overrideFlexformSettingsIfEmpty := addToList(detailPid)
startingpoint = {$pidNachrichtenRecords}
// for use in my fluid template
// pluginTitle = {$llAktuell}
// latest = 0
// recordType = aktuell
// https://forge.typo3.org/issues/52978
useStdWrap = categories
categories.override.cObject < temp.categoryUid
categoryConjunction = or
}
view =< plugin.tx_news.view
}
我仍然不清楚的是,选择中的 recursive = 1
是否没有挫折.实际上,我根本不想检查当前页面的父 uid,但是 WHERE pages.pid IN ({current pid})
总是自动插入.因此recursive = 1
.
What is unclear to me still is if recursive = 1
in the select has no setback. Actually, I don't want to check for the current page's parent uid at all, but WHERE pages.pid IN ({current pid})
is always inserted automatically. Therefore the recursive = 1
.
这篇关于如何在 Typoscript 中获取页面类别(并与 tx_news 一起使用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!