Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

0,1 and more comment/s


Go to End


1839 Views

Avatar
typopunk

Community Member, 6 Posts

4 October 2008 at 3:25am

Edited: 06/10/2008 11:44am

Hello

I just set up an Article Section (holder and page) as decribed in tutorial 2. In addition I now want to display "no comments", "1 comment" or "x comments" - depending on the number of comments.

On the individual page of an article I managed to do so via this setup:

ArticlePage.ss

$Content
<% if Comments.Count %>
      $Comments.Count 
      comment<% if hasManyComments %>s<% end_if %>        
<% else %>
      no comments
<% end_if %>

ArticlePage.php

class ArticlePage_Controller extends Page_Controller {   
  function hasManyComments() {
    $comments = $this->Comments();
    $ccounter = $comments->Count();
    if ($ccounter>1) return true; else return false;
  }
}

On the page this does a good job but it doesn't seem to work inside the <% control Children %> loop of the article holder. The "if Comments.Count" part seems to work but my additional function "hasManyComments" fails. I'm sure that my function needs to look different in that case but I can not find out how...

I'd be happy if someone could lead me to the right direction. Thanks in advance.

EDIT: I finally solved the problem on my own - no support needed anymore.