Jump to:

22977 Posts in 11738 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » Can't hide VirtualPage in navigation menu

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: 755 Views
  • Romano
    Avatar
    Community Member
    13 Posts

    Can't hide VirtualPage in navigation menu Link to this post

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

    Silverstripe 2.4.5

    What should I do?

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Can't hide VirtualPage in navigation menu Link to this post

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

  • Romano
    Avatar
    Community Member
    13 Posts

    Re: Can't hide VirtualPage in navigation menu Link to this post

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

  • zenmonkey
    Avatar
    Community Member
    524 Posts

    Re: Can't hide VirtualPage in navigation menu Link to this post

    You need to do something like

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

  • Romano
    Avatar
    Community Member
    13 Posts

    Re: Can't hide VirtualPage in navigation menu Link to this post

    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.

  • Overt
    Avatar
    Community Member
    5 Posts

    Re: Can't hide VirtualPage in navigation menu Link to this post

    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();
       }
    }

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