5102 Posts in 1520 Topics by 1116 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1198 Views |
-
0,1 and more comment/s - again

6 August 2009 at 6:40am
Hello,
I do have the same problem as Typopunk about how to display "no comments", "1 comment" and "x commentS". Unfortunately he didn't wrote the solution back into the forum. If someone knows the solution - please let me (us) know.
Thanks, MC
PS: Here is the link to Typopunks original post: http://silverstripe.org/archive/show/190741#post190741
-
Re: 0,1 and more comment/s - again

6 August 2009 at 8:50pm
<% if Comments %>
<% if Comments.Count = 1 %>
<p>1 Comment<p>
<% else %>
<p>$Comments.Count Comments</p>
<% end_if %>
<% else %>
<p>No Comments</p>
<% end_if %>Should work
-
Re: 0,1 and more comment/s - again

7 August 2009 at 7:21am
Thanks willr for your quick answer. I tried something like <% if Comments.Count = 1 %> as well.
Unfortunately following error occurs:Parse error: syntax error, unexpected '}' in /tmp/silverstripe-cache-var-www-nena/.cache.var.www.nena.mysite.templates.Layout.ArticleHolder.ss on line 83
If you leave out "=1" the error doesn't show up - of course the result isn't correct.
Do you have any idea?
MC
-
Re: 0,1 and more comment/s - again

15 August 2009 at 3:50pm Last edited: 15 August 2009 3:51pm
I solved this to move the counting to the model:
function CartTotal(){
if(!ShoppingCart::getCart()){
return _t('Webshop.EMPTYCART','Your shoppingcart is empty');
} else {
if(count(ShoppingCart::getCart()) == 1){
return sprintf(_t('Webshop.FILLEDCARTONE','You have %s product in your shoppingcart'), count(ShoppingCart::getCart()));
} else {
return sprintf(_t('Webshop.FILLEDCART','You have %s products in your shoppingcart'), count(ShoppingCart::getCart()));
}
}
}
Little bit different situation, but it should get you going... -
Re: 0,1 and more comment/s - again

16 August 2009 at 11:35pm
Hi Martijn,
Thanks for your answer. I tried to access the function from within the model of the holder but for whatever reason I don't receive any data. As I'm still a beginner with Silverstripe, I'm sure I'm doing something wrong.
I extended the Model and the Controller. Here is a very simply example of what I tried just to make sure that I'm able to receive information directly.
function class ArticleHolder extends Page {
function getTest() {
return "THIS IS A TEST";
}}
class ArticleHolder_Controller extends Page_Controller {
function getTest() {
return "THIS IS A TEST";
}}
In the View I entered:
$getTest
Actually this works very well with ArticlePage, but not with ArticleHolder.
Any idea?
-
Re: 0,1 and more comment/s - again

17 August 2009 at 2:50am
This should work. Did you flush after you editted the template?
-
Re: 0,1 and more comment/s - again

17 August 2009 at 5:58am
Hi Martjin,
I tried it - but it didn't work. But I found out why it didn't work...
$getTest [/] was in the wrong "place".With your help I found the solution:
class ArticlePage extends Page {
function getCommentCounter() {
$comments = DataObject::get("PageComment", "ParentID = " . $this->ID);
if ($comments) {
if ($comments->Count() == 1) return "1comment";
else return $comments->Count() . "comments";
} else return "no comments";
}In the Holder-Template you just have to call $getCommentCounter.
Thanks for your help
MC
}
| 1198 Views | ||
|
Page:
1
|
Go to Top |



