Show category names of current page in TYPO3 8

萝らか妹 提交于 2020-01-25 09:02:41

问题


I am trying to display the category name(s) of the current page on a TYPO3 8 installation. In TYPO3 7 it used to work like this (see below), however now I only receive a random error code and no Text output. Any Ideas?

lib.catclass = CONTENT
lib.catclass {

wrap = <div class="categories">|</div>

table = sys_category
select {
  pidInList = 35 // UiD of your category_page
  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 = TEXT
renderObj.field = title
renderObj.wrap = <li class="category {field:title}">|</li>
renderObj.insertData = 1

}

The corresponding error output is as follows:

    An exception occurred while executing 'SELECT * FROM `sys_category` INNER JOIN `sys_category_record_mm`
    `ON(sys_category_record_mm`.`uid_local=sys_category`.`uid)` ON WHERE 
    (`sys_category`.`pid` IN (35)) AND 
    (sys_category_record_mm.tablenames='pages') AND (`sys_category`.`sys_language_uid` IN (0, -1)) AND 
((`sys_category`.`deleted` = 0) AND (`sys_category`.`t3ver_state` <= 0) AND (`sys_category`.`pid` <> -1) AND (`sys_category`.`hidden` = 0) AND (`sys_category`.`starttime` <= 1546204860) AND
 ((`sys_category`.`endtime` = 0) OR (`sys_category`.`endtime` > 1546204860)))': You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version 
for the right syntax to use near '.`uid_local=sys_category`.`uid)` ON WHERE (`sys_category`.`pid` IN (35)) AND (s' at line 1

回答1:


Try adding a space after ON, so:

join = sys_category_record_mm ON (sys_category_record_mm.uid_local=sys_category.uid)

Also, andWhere has been deprecated since TYPO3 7.1 and has been removed in 8. You need to add that to where and use markers to add the page uid. From the top of my head, that would make it:

lib.catclass = CONTENT
lib.catclass {
  wrap = <div class="categories">|</div>

  table = sys_category
  select {
    pidInList = 35 // UiD of your category_page
    join = sys_category_record_mm ON (sys_category_record_mm.uid_local=sys_category.uid)
    where = sys_category_record_mm.tablenames='pages' AND sys_category_record_mm.uid_foreign = ###pageuid###
    markers {
      pageuid.data = TSFE:id
    }
  }

  renderObj = TEXT
  renderObj.field = title
  renderObj.wrap = <li class="category {field:title}">|</li>
  renderObj.insertData = 1
}

See https://docs.typo3.org/typo3cms/TyposcriptReference/8.7/Functions/Select/#markers for more on markers



来源:https://stackoverflow.com/questions/53978414/show-category-names-of-current-page-in-typo3-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!