Hello Silverstripe Community,
as I read in the Silverstripe Documentation it's impossible to pass Variables inside a control as a parameter. Unfortunately there is no solution written in this doc, so I struggle with this problem for some time now. Here is some Code to explain the problem in detail:
My control function:
function CountComments($newsid)
{
$quer = DataObject::get("PageComment", "ParentID = $newsid");
if($quer)
return $quer->Count();
else
{
return 0;
}
}
So I'm trying to use this function in a template while passing the $ID of another control as a parameter:
<% control LatestNews %>
<li class="newsDateTitle"><a href="$Link" title="Mehr von "{$Title}"">$Title, $TotalItems</a></li>
<li class="newsDateTitle">Geschrieben am $Date.Nice um $Time.Nice von $Author</li>
<li class="newsSummary">$Content <a href="$Link" title="Mehr von "{$Title}"">$Top.CountComments($ID) Kommentar(e) >></a></li>
<% end_control %>
"$Top.CountComments($ID)" is the call I struggle with, I receive the following error message:
Parse error: syntax error, unexpected T_STRING, expecting ')' in D:\WINDOWS\Temp\silverstripe-cacheC--wamp-www-silverstripe-v2.2.2\.cacheC..wamp.www.silverstripe-v2.2.2.tutorial.templates.Layout.HomePage.ss on line 63
When I pass a number instead of the variable the code works fine. So how can I handle this?Thanks in advance.
Florian