Jump to:

3447 Posts in 1032 Topics by 872 members

Template Questions

SilverStripe Forums » Template Questions » 3 fields "Image" on the page

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

Page: 1
Go to End
Author Topic: 1040 Views
  • NtM
    Avatar
    Community Member
    39 Posts

    3 fields "Image" on the page Link to this post

    I need to set up 3 fields "Image" for my template.

    I'm writing like this:

    static $has_many = array(
          "Image" => "Image",
    "Image2" => "Image",
    "Image3" => "Image"
       );

    public function getCMSFields()
       {
          $fields = parent::getCMSFields();   
          
          $fields->addFieldToTab("Root.Content.Main", new ImageField("Image"), "Content");
    $fields->addFieldToTab("Root.Content.Bucket1", new ImageField("Image2"), "Content");
    $fields->addFieldToTab("Root.Content.Bucket2", new ImageField("Image3"), "Content");
       
          return $fields;
       }   

    But the fields does not appear on the tabs "Bucket1" and "Bucket2".

    Can you please help me with that?

  • Willr
    Avatar
    Forum Moderator
    5511 Posts

    Re: 3 fields "Image" on the page Link to this post

    static $has_many = array( ..

    A Page doesn't have 3 has_many images, Rather it should have them as a one to many rather then a many to many. So change that to

    static $has_one = array(..

    The image fields on the other BucketTabs are probably not showing due to the fact you are saying in your addFieldToTab to put them BEFORE a field called 'Content'. This 'Content' Field doesn't exist on the Bucket1, Bucket2 tabs so its not added. Try changing those lines to

    $fields->addFieldToTab("Root.Content.Bucket1", new ImageField("Image2"));
    $fields->addFieldToTab("Root.Content.Bucket2", new ImageField("Image3"));

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