Jump to:

5453 Posts in 1674 Topics by 1198 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Add Function & CMS Field ONLY to Menu Pages

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

Page: 1
Go to End
Author Topic: 854 Views
  • pinkp
    Avatar
    Community Member
    168 Posts

    Add Function & CMS Field ONLY to Menu Pages Link to this post

    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!?

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: Add Function & CMS Field ONLY to Menu Pages Link to this post

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

  • pinkp
    Avatar
    Community Member
    168 Posts

    Re: Add Function & CMS Field ONLY to Menu Pages Link to this post

    Works like a charm! thank you!!

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