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:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

In a pickle


Go to End


3 Posts   1546 Views

Avatar
TerryMiddleton

Community Member, 108 Posts

24 July 2009 at 10:34am

I use Page.ss for most (99%) of all my pages. I have a couple of pages that has part of the content that needs to be hidden unless you are logged in.

It started as just one page so it was easy because I if used a <% if URLSegment != Page %> Show Content <% else %> Show the one page content and then check to see if they are logged in (currentmember)

Now I have 2-3 pages that I need to do this for and I'm wondering if there is a way to do a Case statement on URLSegment?

My only other alt which I don't find effecient is to create a page type for each page.

Anyone with a good suggestion.

Terry

Avatar
Willr

Forum Moderator, 5523 Posts

24 July 2009 at 2:48pm

Now I have 2-3 pages that I need to do this for and I'm wondering if there is a way to do a Case statement on URLSegment?

The template parser doesn't support a switch / case statement. It does support if .. else_if .. else_if .. else which pretty much does the same thing. Though depending on how complex you want to get it might be cleaner to do a PHP which returns the result. Keeps the template much cleaner

function ShowProtectedContent() {
$return = true;
switch($this->URLSegment) {
  case 'home': $return = false; break;
...
}
return $return;
}

<% if ShowProtectedContent %>
...
<% end_if %>

Avatar
TerryMiddleton

Community Member, 108 Posts

25 July 2009 at 8:48am

willr,

As always...thanks a bunch. Worked perfectly.

Terry