Jump to:

23456 Posts in 18905 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » In a pickle

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

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

Page: 1
Go to End
Author Topic: 1021 Views
  • TerryMiddleton
    Avatar
    Community Member
    108 Posts

    In a pickle Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: In a pickle Link to this post

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

  • TerryMiddleton
    Avatar
    Community Member
    108 Posts

    Re: In a pickle Link to this post

    willr,

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

    Terry

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