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.

General Questions

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

Can't hide VirtualPage in navigation menu


Reply

6 Posts   863 Views

Avatar
Romano

13 July 2011 at 12:28am Community Member, 13 Posts

VirtualPage defined as child page. "ShowInMenu" does not affect in <% control Children %>.

Silverstripe 2.4.5

What should I do?

Avatar
swaiba

13 July 2011 at 1:23am Forum Moderator, 1796 Posts

I don't know 100% but I can tell you that I do this...

http://www.silverstripe.org/customising-the-cms/show/15861#post299233

note - this ain't the best for multi-lingual...

Avatar
Romano

13 July 2011 at 2:14am Community Member, 13 Posts

Thanks, but not in admin panel. How to exclude the "VirtualPage" link from navigation menu on website?

Avatar
zenmonkey

15 July 2011 at 2:39am Community Member, 528 Posts

You need to do something like

<% control Menu(1) %>
<% if ClassName != VirtualPage %>
<a href="$Link">$MenuTitle</a>
<% end_if %>
<% end_control %>

Avatar
Romano

21 July 2011 at 6:19am Community Member, 13 Posts

Look at this code (VirtualPage.php):

         // We also want to copy ShowInMenus, but only if we're copying the
         // source page for the first time.
         if($this->isChanged('CopyContentFromID')) {
            $this->ShowInMenus = $source->ShowInMenus;
         }

We also want to copy ShowInMenus, but only if we're copying the source page for the first time.

It always copies the ShowInMenus!

My temporary solution - comment this line code. But I would like to install ShowInMenus manually because some virtual pages should be displayed.

Avatar
Overt

5 September 2012 at 7:11am Community Member, 5 Posts

You need to create your own virtual page by extending an original:

class MyVirtualPage extends VirtualPage {
   function getVirtualFields() {
      $myNonVirtualFields = array(
         "ShowInMenus"
      );
      $virtualFields = parent::getVirtualFields();
      foreach($virtualFields as $key => $field) {
         if(!in_array($field, $myNonVirtualFields)) $myVirtualFields[] = $field;
      }
      return $myVirtualFields;
   }
}

class MyVirtualPage_Controller extends VirtualPage_Controller {
   public function init() {
      parent::init();
   }
}