Jump to:

3393 Posts in 976 Topics by 852 members

Template Questions

SilverStripe Forums » Template Questions » Problem with <%if > control

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

Page: 1 2 3
Go to End
Author Topic: 7961 Views
  • J2-Paul
    Avatar
    Community Member
    51 Posts

    Problem with <%if > control Link to this post

    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?

  • Pigeon
    Avatar
    Community Member
    243 Posts

    Re: Problem with <%if > control Link to this post

    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.

  • Tonyair
    Avatar
    Community Member
    81 Posts

    Re: Problem with <%if > control Link to this post

    I have the same problem with:

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

  • Pigeon
    Avatar
    Community Member
    243 Posts

    Re: Problem with <%if > control Link to this post

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

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

  • Tonyair
    Avatar
    Community Member
    81 Posts

    Re: Problem with <%if > control Link to this post

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

  • Juanitou
    Avatar
    Community Member
    322 Posts

    Re: Problem with <%if > control Link to this post

    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

  • Pigeon
    Avatar
    Community Member
    243 Posts

    Re: Problem with <%if > control Link to this post

    Thanks Juanitou

  • Tonyair
    Avatar
    Community Member
    81 Posts

    Re: Problem with <%if > control Link to this post

    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

    7961 Views
Page: 1 2 3
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.