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

Can't hide VirtualPage in navigation menu


Go to End
Reply


6 Posts   1069 Views

Avatar
Romano

Community Member, 13 Posts

13 July 2011 at 12:28am

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

Silverstripe 2.4.5

What should I do?

Avatar
swaiba

Forum Moderator, 1824 Posts

13 July 2011 at 1:23am

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

Community Member, 13 Posts

13 July 2011 at 2:14am

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

Avatar
zenmonkey

Community Member, 532 Posts

15 July 2011 at 2:39am

You need to do something like

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

Avatar
Romano

Community Member, 13 Posts

21 July 2011 at 6:19am

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

Community Member, 5 Posts

5 September 2012 at 7:11am

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