Jump to:

3434 Posts in 1026 Topics by 866 members

Template Questions

SilverStripe Forums » Template Questions » Use <% if %>

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

Page: 1
Go to End
Author Topic: 375 Views
  • bubu333
    Avatar
    Community Member
    8 Posts

    Use <% if %> Link to this post

    I have a problem.Example:I have a image which show in both pages are contact page and gallery page
    So,i writed in file .ss :
    <% if ClassName=ContactPage %>
    <img .... />
    <% end_if %>

    But it's just work in ContactPage so i write again
    <% if ClassName=ContactPage || ClassName=GalleryPage %>
    <img .... />
    <% end_if %>
    And after ?flush=all,my browser show error:Parse error: syntax error, unexpected '}'...
    I want to ask you,we can use "OR,AND" or " ||,&& " in <% if %> ???

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Use <% if %> Link to this post

    Is this on 3.0 or 2.4? I tested 3.0 and <% if ClassName = HomePage || ClassName = GalleryPage %><p>hi</p><% end_if %> worked fine for me. In 2.4 you'll need to move the functions to the Page_Controller class.

    // page.php
    function ShowGallery() {
    return ($this->ClassName == "ContactPage" || $this->ClassName == "GalleryPage");
    }

    // template
    <% if ShowGallery %>...

  • bubu333
    Avatar
    Community Member
    8 Posts

    Re: Use <% if %> Link to this post

    Thank you so much!It works fine!

    375 Views
Page: 1
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.