1

I looking for normal (fluid) way add in tx_news (Template->News->List) count of comments from table EXT: news_comments for each entity. For Example:

News 1 (Comments:5)  
Date  
Description  
-----
News 2 (Commnets: 0)  
Date  
Description  
Cœur
  • 37,241
  • 25
  • 195
  • 267
Oleg V Karun
  • 726
  • 1
  • 6
  • 29

1 Answers1

0

Ok i create simple ViewHelper for this. I guess not allowed if you have few thousand posts but if few hundred - all will be ok. First we nned add ViewHelper in our project EXT

<?php

namespace HIT\huskytheme\ViewHelpers\News;

class CountCommnetsViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {

    /**
     * @var \DRCSystems\NewsComment\Domain\Repository\CommentRepository
     * @inject
     */
    protected $commentRepository = null;

    /**
     * 
     * @param int $news
     * @return string
     */
    public function render($news) {
        return count($this->commentRepository->getCommentsByNews($news));
    }

}

Please change 'namespace' for your Vendor name and ViewHelper location.

Then in copy tx_news fluid Templates somewhere and add them by TS. In Templates->Partitials->List->Item.html (or you path) you can call ViewHelper and use like that:

{namespace s=HIT\huskytheme\ViewHelpers} 
...
Comments: ({s:news.countCommnets(news: newsItem.uid)})

Or other template - just add corect newsItem.uid inside and againe you own namesapce mast be called.

Oleg V Karun
  • 726
  • 1
  • 6
  • 29