typo3typoscripttypo3-6.2.xtt-news

TYPO3 change meta value in specified tt_news category


I have a question about tt_news and SEO. I would like to change some meta value in news from specified category. I try with this code but it didn't work:

[globalVar = GP:tx_ttnews|tt_news > 0] && [globalVar = GP:tx_ttnews|cat = 13]
   page = PAGE
   page.meta.robots = noindex
[global]

Any suggestion?


Solution

  • The condition [globalVar = GP:param = foo] checks if $_GET or $_POST arrays (in this order) contains the param with value foo, but it soen't check the record for used categories, therefore you need to write custom condition (reference) into typo3conf/AdditionalConfiguration.php (mandatory location for TYPO3 6.x! in 4.x that would be common typo3conf/localconf_local.php) which will check if there's param with single news and then will check tt_news_cat_mm table for relations between News and Category, ready to use sample is:

    /** For ext:tt_news only! (not for ext:news) */
    function user_ttNewsInCat($catUid) {
        $newsParams = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('tx_ttnews');
    
        // If news is in params then check categories, otherwise skip it
        if (!is_null($newsParams) && is_array($newsParams) && intval($newsParams['tt_news']) > 0) {
            $newsUid = intval($newsParams['tt_news']);
            $matchesInMM = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'tt_news_cat_mm', "uid_local={$newsUid} AND uid_foreign={$catUid}");
    
            if (count($matchesInMM)>0) return TRUE;
        }
    
        return FALSE;
    }
    

    And its usage in typoscript is:

    [userFunc = user_ttNewsInCat(13)]
      page.meta.robots = noindex
    [end]