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.

Data Model Questions /

Menu with alternating pages if logged in or not?


Go to End
Reply


11 Posts   4389 Views

Avatar
banal

Community Member, 901 Posts

10 August 2009 at 11:14pm

Edited: 10/08/2009 11:15pm

Ouch. That is indeed a rather inflexible design. I for one wouldn't care too much about the design when I'm admin, since for me it would be more important to actually see the pages when I'm logged in, so that I can verify the contents. But to each his own I guess :)

Additionally, you could check the return value of:

Director::get_site_mode();

If in the CMS, you should get 'cms' as return value, 'site' otherwise.
Example code:

class AnonPage extends Page {
   public function canView($member = null) {
      
      if(Director::get_site_mode() == 'cms'){
         return parent::canView($member);
      }
      
      if(!$member || !(is_a($member, 'Member')) || is_numeric($member))
         $member = Member::currentUser();
         
      return $member ? false : true;
   }
   
   function can($type) {
      return $type == 'view' ? $this->canView() : parent::can($type);
   }
}

Avatar
zenmonkey

Community Member, 532 Posts

29 August 2009 at 7:14am

Okay maybe I'm way of here, but doesn't a combination <% if CurrentMember %> in the templates and using the Who Can View This Page in the Behavior section accomplish this? Thats how I'm controlling different menus for Logged in Users and General Public. But may this too basic for what you really need.

Here is my Navigation.ss

<ul class="grid_9 topnav">
   <% if CurrentMember %>
   <% control Menu(1) %>
   <% if Title != "Home" %>   
   <li>
      <a href="$Link">$MenuTitle.XML</a>
      <% if Children %>   
      <ul class="subnav">
         <% control Children %>
         <% if Children %>
         <li>
            <a href="$Link">$MenuTitle.XML</a>
            <ul class="subSubnav">
            <% control Children %>
               <li><a href="$Link">$MenuTitle.XML</a></li>
            <% end_control %>
            </ul>                           
         </li>
         <% else %>
         <li><a href="$Link">$MenuTitle.XML</a></li>
         <% end_if %>
         
         <% end_control %>
      </ul>
      <% end_if %>
   </li>
   <% end_if %>   
   <% end_control %>
   <% else %>
   <% control Menu(1) %>
   <% if Title != "Home" %>   
   <li>
      <a href="$Link">$MenuTitle.XML</a>
      <% if Children %>   
      <ul class="subnav">
         <% control Children %>
         <% if Children %>
         <li>
            <a href="$Link">$MenuTitle.XML</a>
            <ul class="subSubnav">
            <% control Children %>
               <li><a href="$Link">$MenuTitle.XML</a></li>
            <% end_control %>
            </ul>                           
         </li>
         <% else %>
         <li><a href="$Link">$MenuTitle.XML</a></li>
         <% end_if %>
         
         <% end_control %>
      </ul>
      <% end_if %>
   </li>
   <% end_if %>   
   <% end_control %>
   <li><a href="where-to-buy/">Where to Buy</a></li>
   <% end_if %>
</ul>

Sorry I don't indent my Controls and and If Statements if only to try and keep the output code cleaner.

But logged in Users Get different Menu options Than the General Public.

Avatar
JonoM

Community Member, 103 Posts

5 September 2011 at 5:49pm

Hello,

I'm encountering a similar problem to what was discussed here - can anyone suggest a way of determining if someone is viewing the CMS or the front-end of a website? Director::get_site_mode() previously sounded perfect but it is deprecated so I'm not sure what I can do instead.

I have tried to use canView to hide a certain page based on a set of conditions but I want it to always be editable in the CMS even if the logged in Admin doesn't meet those conditions. However - I would like those conditions to still apply to the Admin when viewing the front-end site and hide the page if they're not met.

Really appreciate any help anyone can offer.

Thanks

Go to Top