如何在Typoscript中获取页面类别(并与tx_news一起使用)

时间:2015-02-14 14:55:21

标签: typo3 typoscript tx-news

我想读出一个页面的系统类别,以便与tx_news一起使用(显示与页面具有相同类别的新闻 - 因为tx_news正在使用系统类别)。

我一直在寻找原生解决方案,希望通过getText,例如: plugin.tx_news.settings.categories.data = page:categories 但这似乎还不存在

此外,我尝试使用sys_category_records_mm简化查询,其中包含该案例所需的所有信息,但TYPO3抱怨“$ TCA数组中没有条目”:

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 = |,
  }
}

这样会很好,但不允许这样做。

3 个答案:

答案 0 :(得分:2)

这是一个适用于我的设置的解决方案。编辑器为页面选择类别,并获取属于该类别的所有新闻项目。

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

答案 1 :(得分:1)

我找到了这个example(用德语)并修改它以显示类别UID。

以下TypoScript将显示以逗号分隔的当前页面的所有类别的UID。

10 = CONTENT
10 {
  table = pages
  select {
    uidInList.field = uid
    pidInList = 1 # UID or list of UIDs, where your categories are saved 
    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 = {field:uid}
    where.insertData = 1
    orderBy = sys_category.sorting
  }
  renderObj = TEXT
  renderObj {
    field = catUid
    wrap = |,
  }
  # HACK
  # If category is empty, the mechanism below won't work
  # As long as I don't know how to query if this is empty or not,
  # just add an imaginary extra category!
  wrap = 12345,|
}

不幸的是,您必须手动将pidInList设置为存储类别的UID列表。

答案 2 :(得分:0)

寻找页面的cat-id: 我是这样做的:

lib.cat = CONTENT
lib.cat {
  wrap = |
  table = sys_category
  select {
     pidInList = 1
     selectFields  = sys_category.uid, sys_category.title
     max = 1
     join = sys_category_record_mm ON(sys_category_record_mm.uid_local = sys_category.uid)
     where = sys_category_record_mm.tablenames='pages'
     andWhere.dataWrap = sys_category_record_mm.uid_foreign = {TSFE:id}
  }
  renderObj = COA
  renderObj {
     10 = TEXT
     10 {
        field = uid
        wrap = class="category|
     }
     20 = TEXT
     20 {
        field = title
        case = lower
        stdWrap.noTrimWrap = | |"|
     }
  }
}