3069 Posts in 868 Topics by 650 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1159 Views |
-
Parse Error in Template

4 October 2010 at 5:02am Last edited: 4 October 2010 5:03am
Having followed all of the tutorials, I decided to modify the ArticleHolder type so that it could have ArticleHolder children, which in turn would have ArticlePage children. I changed the $allowed_children setting without a problem, however I get a parse error with my modified ArticleHolder.ss, which checks if the children are ArticleHolders or Article Pages and only uses the required fields.
This is my /themes/tutorial/templates/Layout/ArticleHolder.ss:
<div id="Content" class="typography">
$Content
<ul id="NewsList">
<% if this->Child()->ClassName = ArticlePage %>
<% control Children %>
<li class="newsDateTitle"><a href="$Link" title="Read more on $Title">$Title</a></li>
<li class="newsDateTitle">$Date.Nice, $Qualification</li>
<li class="newsSummary">$Description <a href="$Link" title="Read more on $Title">Read more >></a></li>
<% end_control %>
<% else %>
<% control Children %>
<li class="newsDateTitle"><a href="$Link" title="Read more about $Title">$Title</a></li>
<li class="newsDateTitle">$Qualification</li>
<li class="newsSummary">$Description <a href="$Link" title="Read more about $Title">Read more >></a></li>
<% end_control %>
<% end_if %>
</ul>
</div>and this is the error I get:
Parse error: syntax error, unexpected '}' in /tmp/silverstripe-cache-home-irevise-public_html/.cache.home.irevise.public_html.themes.tutorial.templates.Layout.ArticleHolder.ss on line 58
I've searched through ArticleHolder.ss, and can't find any out-of-place braces. Can anybody tell me what's going wrong here?
-
Re: Parse Error in Template

4 October 2010 at 5:57am
Hi,
The template errors rarely point to the exact issue in my expiernce... what I think is wrong above is...
<% if this->Child()->ClassName = ArticlePage %>
i)you never need "this" in templates you are in the controller "context" by default each <% control %> shifts the context and things like $Top can be used to use the controller context when still in a control
ii)to call a method / object use the '.' not the '->'
I'd suggest putting a function like this in the controller...
function IsChildClassName($str)
{
return ($this->Child()->ClassName == $str);
}then replace the template line with....
<% if IsChildClassName(ArticlePage) %>
(note all untested)
there might be a "Child.Classname = " possible (comething like Top.Classname would work I am sure) and if it is that would make the controller function redundant. It is good practice I believe to put anything complicated in the controller and keep the template very simple
Barry
-
Re: Parse Error in Template

4 October 2010 at 7:59am Last edited: 4 October 2010 9:04am
Thank you for the reply.
I've changed the code, and it gets rid of the plain-text parsing error, however SilverStripe now shows its 'Website Error: The website server has not been able to respond to your request.' message. I've done some testing, and this is definitely down to the ArticleHolder.ss if-else construct. Can anybody help me with this error?
-
Re: Parse Error in Template

4 October 2010 at 9:10am Last edited: 4 October 2010 9:12am
That sounds like a PHP error, do you have the following in you mysite/_config.php?
Director::set_environment_type('dev');
check out...
http://doc.silverstripe.org/common-problemsp.s. I did mention the code was untested!
-
Re: Parse Error in Template

5 October 2010 at 5:17am
It seems that the problem is with the Child() function - it doesn't exist. I've been trying to fiddle with ChildrenOf() to make it work, but I can't. Can anybody see what could be fixed in that line to make it work?
-
Re: Parse Error in Template

5 October 2010 at 6:55am
You might want to add a check for Child in the IsChildClassName method:
function IsChildClassName($str){
if($this->Child()){
return ($this->Child()->ClassName == $str);
}
} -
Re: Parse Error in Template

5 October 2010 at 7:00am Last edited: 5 October 2010 9:53am
Alright, from looking at this it seems that there are no children, there are only parents!
As in each page records it's parent, so you can find a pages children by using...
$dosChildPages = DataObject::get('Page','ParentID='.$iPageID);
So now you have to look at your logic again and decide whether it is contains at least one page that is of classname=xyz or something else. Looking back on you original code it was obvious it needed changing because it always assumed a return (by calling ->Classname without knowing if it even had one object/child) and also assumed only one object would be return (pages can have many children).
I'd assumed your php was ok, but you were learning templates, sorry.
btw i'd advise using netbeans or similar to provide code completion, then you'd aways know which method (and get it typed in) with the minimum of effort
-
Re: Parse Error in Template

9 October 2010 at 2:38am
Sorry for the lack of reply in a while.
It seems that coding the way I was originally intending is throwing up too many complications, so I've re-worked my logic to avoid this problem. Thank you again to everybody who contributed in trying to fix my issue.
| 1159 Views | ||
|
Page:
1
|
Go to Top |



