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.

Customising the CMS

Add Function & CMS Field ONLY to Menu Pages


Reply

3 Posts   895 Views

Avatar
pinkp

30 May 2010 at 5:34am Community Member, 168 Posts

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

30 May 2010 at 11:40am Forum Moderator, 5511 Posts

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

30 May 2010 at 7:54pm Community Member, 168 Posts

Works like a charm! thank you!!