17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1613 Views |
-
Pass Variables inside a control

16 July 2008 at 7:51pm
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
-
Re: Pass Variables inside a control

16 July 2008 at 8:37pm
If you are just trying to show the number of comments on the page you can just do $Comments.Count in the template. Im pretty sure that will output the amount of comments that page has.
-
Re: Pass Variables inside a control

16 July 2008 at 9:24pm
No, it's not possible to do that in the SS templating language.
Typically the templates are used for just dumb tasks like outputting variables and looping through iterative data from the model/controller, so if you're doing more complex actions, it's better (and most of the time easier) to just put the logic on the model and output it directly in the template.
| 1613 Views | ||
|
Page:
1
|
Go to Top |



