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   901 Views

Avatar
pinkp

Community Member, 168 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, 5513 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, 168 Posts

30 May 2010 at 7:54pm

Works like a charm! thank you!!