Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » How do add an additional 'Content' box to SS?

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 1893 Views
  • Mishy
    Avatar
    Community Member
    24 Posts

    How do add an additional 'Content' box to SS? Link to this post

    I have added a box to my CMS using a HomePage.php page. When I view the 'Scroller' box in the CMS it is only a single line long and is only text. Please would someone let me know how to get the functionality and size of the 'Content' box in an additional input box.

    Many thanks
    Michelle

    class HomePage extends Page {
       static $db = array(
          'Scroller' => 'Text'
          
       );
       
       function getCMSFields() {
          $fields = parent::getCMSFields();
          $fields->addFieldToTab('Root.Content.Main', new TextField('Scroller'), 'Content');
          return $fields;
          }
          
       static $has_one = array(
    );
    }

    class HomePage_Controller extends Page_Controller {
       
    }

  • Liam
    Avatar
    Community Member
    470 Posts

    Re: How do add an additional 'Content' box to SS? Link to this post

    Change it to the htmltext type.

    'Scroller' => 'HTMLText'

    Then,

    $fields->addFieldToTab('Root.Content.Main', new HtmlEditorField('Scroller'), 'Content');

    http://doc.silverstripe.com/doku.php?id=htmleditorfield

    You can see all the ones you can use in the docs.

    http://doc.silverstripe.com/doku.php?id=form-field-types

  • Mishy
    Avatar
    Community Member
    24 Posts

    Re: How do add an additional 'Content' box to SS? Link to this post

    That worked an absolute treat. Thank you so much LeeUmm.

    Cheers
    Michelle

  • pxlpshr
    Avatar
    Community Member
    14 Posts

    Re: How do add an additional 'Content' box to SS? Link to this post

    I've been trying to do the same (following along with the tutorials)... and I can see the new fields in the CMS, but they aren't saving to the database (except the team photo). The variables are unique as far as I can tell:

    <?php

    class TeamPage extends Page {
    static $db = array(
    );
    static $has_one = array(
    'Photo' => 'Image',
    'JobPosition' => 'Text',
        'JobTitle' => 'Text',
        'JobLocation' => 'Text'
    );
       
    function getCMSFields() {
    $fields = parent::getCMSFields();
        $fields->addFieldToTab('Root.Content.Main', new TextField('JobPosition'), 'Content');
        $fields->addFieldToTab('Root.Content.Main', new TextField('JobTitle'), 'Content');
        $fields->addFieldToTab('Root.Content.Main', new TextField('JobLocation'), 'Content');    
    $fields->addFieldToTab('Root.Content.Images', new ImageField('Photo'));
        return $fields;
    }
    }

    class TeamPage_Controller extends Page_Controller {
       
    }
    ?>

  • Liam
    Avatar
    Community Member
    470 Posts

    Re: How do add an additional 'Content' box to SS? Link to this post

    You need to put those fields in the $db array, not the has_one array unless you're building relationships between pages. Leave the photo in the has_one though.

    Then run domain.com/db/flush=1

  • grilldan
    Avatar
    Community Member
    135 Posts

    Re: How do add an additional 'Content' box to SS? Link to this post

    The code should be something like this:

       static $db = array(
          'Photo' => 'Image',
          'JobPosition' => 'Text',
          'JobTitle' => 'Text',
          'JobLocation' => 'Text'
       );

  • pxlpshr
    Avatar
    Community Member
    14 Posts

    Re: How do add an additional 'Content' box to SS? Link to this post

    beautiful!!! thanks liam.

    starting to really like silverstripe, just gotta get a little further over this hump.

  • pxlpshr
    Avatar
    Community Member
    14 Posts

    Re: How do add an additional 'Content' box to SS? Link to this post

    Ok, now I'm stuck again.

    I tried adding more than one image to static $db = array( and it threw a bunch of errors. But everything works fine if I only have one image located in: static $has_one = array(

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