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.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Add Function & CMS Field ONLY to Menu Pages


Go to End


3 Posts   1348 Views

Avatar
pinkp

Community Member, 182 Posts

30 May 2010 at 5:34am

I have this code for Page.php

class Page extends SiteTree {
	
	public static $db = array(
	);
	
	public static $has_one = array(
	'MenuImg' => 'Image',
	'MenuImg2' => 'Image'
	);
	
		function getCMSFields()
   {
	   
      $fields = parent::getCMSFields();
	  $fields->addFieldToTab("Root.Content.MenuImages", new ImageField('MenuImg','Menu Image')); 
      $fields->addFieldToTab("Root.Content.MenuImages", new ImageField('MenuImg2','Menu Image Rollover'));  

	  return $fields;
 }
}

I only want the "Menu Images" tab to appear in the CMS on pages that are ticked "Show in Menus" is this possible thanks!?

Avatar
Willr

Forum Moderator, 5523 Posts

30 May 2010 at 11:40am

Perhaps use

$fields = parent::getCMSFields(); 

if($this->ShowInMenus) {
$fields->addFieldToTab("Root.Content.MenuImages", new ImageField('MenuImg','Menu Image')); 
$fields->addFieldToTab("Root.Content.MenuImages", new ImageField('MenuImg2','Menu Image Rollover'));
}
 
return $fields; 
}

Avatar
pinkp

Community Member, 182 Posts

30 May 2010 at 7:54pm

Works like a charm! thank you!!