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.

Template Questions

Problem with <%if > control


Go to End
Reply

19 Posts   8676 Views

Avatar
J2-Paul

7 June 2010 at 9:55am Community Member, 51 Posts

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
Pigeon

7 June 2010 at 10:14am (Last edited: 7 June 2010 8:22pm), Community Member, 243 Posts

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

7 June 2010 at 7:31pm Community Member, 81 Posts

I have the same problem with:

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

Avatar
Pigeon

7 June 2010 at 8:23pm Community Member, 243 Posts

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

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

Avatar
Tonyair

7 June 2010 at 8:38pm Community Member, 81 Posts

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

Avatar
Juanitou

7 June 2010 at 8:42pm Community Member, 323 Posts

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
Pigeon

8 June 2010 at 2:16am Community Member, 243 Posts

Thanks Juanitou :)

Avatar
Tonyair

8 June 2010 at 3:51am (Last edited: 8 June 2010 4:02am), Community Member, 81 Posts

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