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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

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

Page Accesss to Not Logged in viewers


Go to End


6 Posts   1000 Views

Avatar
JonShutt

Community Member, 244 Posts

2 May 2012 at 9:08am

Hi,

in the 'access' tab it's really easy to set a page so it can only be access by logged in members, or specific groups. But i'm wanting a page to only be visible (and shown in the menus) when the user is logged out.

Has anyone come across an easy solution for this?

Avatar
novaweb

Community Member, 116 Posts

2 May 2012 at 10:33am

In Page.ss:


<% if CurrentMember %>

<p>A logged in person can see this</p>

<% else %>

<p>A logged out person can see this</p>


<% end_if %>

Have fun!
Nova

Avatar
JonShutt

Community Member, 244 Posts

2 May 2012 at 10:42am

that will work for the page content itself, assuming the page has it's own page type and tempalte, but i'm really looking at something that will remove the item from the menu...

Avatar
novaweb

Community Member, 116 Posts

2 May 2012 at 11:04am

Yes you will need to either edit the existing Page.ss or create your own Page Type.

In Navigation.ss:

<% if CurrentMember %>
<ul>
 	<% control Menu(1) %>	  
  		<li><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode"><span>$MenuTitle.XML</span></a></li>
   	<% end_control %>
 </ul>
<% else %>
<ul>
    <li><a href="">Viewable by Logged Out Link</a></li>
</ul>
<% end_if %>

This can also be achieved other ways, I'm just trying to keep it simple.

Avatar
JonShutt

Community Member, 244 Posts

2 May 2012 at 11:13am

thanks... You're example would replace the whole menu, which is fine if this is what you need. in my case i just have a few pages. However, you've got me thinking, and I think i'll just need to add another tickbox to the behaviour tab, and then do something like this

<ul>
<% control Menu(1) %>
<% if CurrentMember %>
<% if DontShowToLoggedInMemebers %>
<% else %>

<li><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode"><span>$MenuTitle.XML</span></a></li>

<% end_if %>
<% else %>

<li><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode"><span>$MenuTitle.XML</span></a></li>

<% end_if %>
<% end_control %>
</ul>

that should work! thanks

Avatar
novaweb

Community Member, 116 Posts

2 May 2012 at 11:16am

Yeah was thinking something similar. Good luck!