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.

Archive /

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

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

How do add an additional 'Content' box to SS?


Reply


8 Posts   1993 Views

Avatar
Mishy

Community Member, 24 Posts

8 September 2008 at 4:59am

Edited: 08/09/2008 5:20am

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

Avatar
Liam

Community Member, 470 Posts

8 September 2008 at 5:52am

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

Avatar
Mishy

Community Member, 24 Posts

8 September 2008 at 6:05am

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

Cheers
Michelle

Avatar
pxlpshr

Community Member, 14 Posts

10 September 2008 at 8:16am

Edited: 10/09/2008 8:16am

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 {
   
}
?>

Avatar
Liam

Community Member, 470 Posts

10 September 2008 at 8:22am

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

Avatar
grilldan

Community Member, 135 Posts

10 September 2008 at 8:26am

The code should be something like this:

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

Avatar
pxlpshr

Community Member, 14 Posts

10 September 2008 at 8:27am

beautiful!!! thanks liam.

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

Avatar
pxlpshr

Community Member, 14 Posts

10 September 2008 at 12:16pm

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(