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

Use <% if %>


Go to End


3 Posts   809 Views

Avatar
bubu333

Community Member, 8 Posts

10 November 2012 at 4:00pm

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 %> ???

Avatar
Willr

Forum Moderator, 5523 Posts

11 November 2012 at 4:23pm

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 %>...

Avatar
bubu333

Community Member, 8 Posts

12 November 2012 at 4:39am

Thank you so much!It works fine!