1
votes

I have a list view and a detail view plugin of tx_news on the same page. When I enter the page without a news-id parameter, I would like to show the latest news record instead. Is there a way to do that?

I found that a feature request for this was rejected here: https://forge.typo3.org/issues/67012

1

1 Answers

2
votes

The solution is contained within the documentation. I did not find it there until I had figured out most of it myself and was looking for a specific method that I needed (useStdWrap). Here it is:

https://docs.typo3.org/typo3cms/extensions/news/AdministratorManual/BestPractice/IntegrationWithTypoScript/Index.html#fallback-in-detail-view-if-no-news-found

# TS SETUP:
plugin.tx_news.settings {
        overrideFlexformSettingsIfEmpty = singleNews,cropMaxCharacters,dateField,timeRestriction,orderBy,orderDirection,backPid,listPid,startingpoint
        useStdWrap = singleNews

        singleNews.stdWrap.cObject = CONTENT
        singleNews.stdWrap.cObject {
                table = tx_news_domain_model_news
                select {
                        max = 1
                        orderBy = datetime
                        # ENTER PID OF YOUR NEWS RECORDS HERE
                        pidInList = 3
                }
                renderObj = TEXT
                renderObj.field = uid
        }
}

This code does NOT include the possibility to filter by category and it OVERWRITES any existing configuration lists in overrideFlexformSettingsIfEmpty and useStdWrap.

If you need category filtering and/or want to be less destructive on the two configuration lists, here is an extended example:

# TS SETUP:
plugin.tx_news.settings {
        overrideFlexformSettingsIfEmpty := addToList(singleNews)
        useStdWrap := addToList(singleNews)

        singleNews.stdWrap.cObject = CONTENT
        singleNews.stdWrap.cObject {
                table = tx_news_domain_model_news
                select {
                        max = 1
                        orderBy = datetime
                        # ENTER PID OF YOUR NEWS RECORDS HERE
                        pidInList = 3
                        join = sys_category_record_mm ON (tx_news_domain_model_news.uid = sys_category_record_mm.uid_foreign)
                        # ENTER UID OF YOUR CATEGORY HERE (look it up in table sys_category)
                        where = sys_category_record_mm.uid_local = 2
                }
                renderObj = TEXT
                renderObj.field = uid
        }
}