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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Template Questions /

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

Problem with <%if > control


Go to End


19 Posts   12182 Views

Avatar
J2-Paul

Community Member, 51 Posts

7 June 2010 at 9:55am

This control block

<% if $URLSegment='edit' %>
$StudentEdit
<% else_if $URLSegment='add' %>
$StudentAdd
<% end_if %>

is throwing this error.

Parse error: syntax error, unexpected '}' in C:\WINDOWS\Temp\silverstripe-cacheE--websites-_SilverStripe-Reception-Screen.v2.4.0\.cacheE..websites._SilverStripe.Reception-Screen.v2.4.0.themes.J2.templates.Layout.StudentEdit.ss on line 222

Yet went I use the %StudentEdit and $StudentAdd in the same template without the if control all is fine.

Any ideas anyone?

Avatar
dhensby

Community Member, 253 Posts

7 June 2010 at 10:14am

Edited: 07/06/2010 8:22pm

SS's templating language is very simple and doesn't allow for great amount of logic.

When doing comparisons, you don't need to use quote marks or apostrophes.

  <% if URLSegment = edit %> 
         $StudentEdit 
      <% else_if URLSegment = add %> 
         $StudentAdd 
      <% end_if %>

Personally, i would never compare URLSegments in the template as the site administrator will be able to change these, thus breaking the site.

Avatar
Tonyair

Community Member, 81 Posts

7 June 2010 at 7:31pm

I have the same problem with:

<% if $ClassName = HomePage %>
<% include Menu2 %>
<% end_if %>

Avatar
dhensby

Community Member, 253 Posts

7 June 2010 at 8:23pm

Sorry, also in the <% %> you must not use the $ before the variable name.

<% if ClassName = HomePage %> 
<% include Menu2 %> 
<% end_if %>

Avatar
Tonyair

Community Member, 81 Posts

7 June 2010 at 8:38pm

thx, but what about that?
<% if ClassName != ArticleHolder && ClassName != StaffHolder %>
<% include Menu2 %>
<% end_if %>

Avatar
Juanitou

Community Member, 323 Posts

7 June 2010 at 8:42pm

Please check docs: http://doc.silverstripe.org/templates#if_blocks

No quotes around values, no $ before properties, only four simple boolean operators.

Hope it helps,
Juan

Avatar
dhensby

Community Member, 253 Posts

8 June 2010 at 2:16am

Thanks Juanitou :)

Avatar
Tonyair

Community Member, 81 Posts

8 June 2010 at 3:51am

Edited: 08/06/2010 4:02am

Of course i checked it before to didn't ask u stupid questions and it's logical that PHP property name always started with $ sign so it's not obvious and if u look at <% if Property != value &> here is strange sign & at the end of the row

and

if ( $Property && $Property)
it's the same as if ( $Property == TRUE && $Property == TRUE)

don't be angry about my questions, just manual must be corrected and there won't such questions anymore

P.S. Sorry

Go to Top