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

Multiple Editable Areas on a Single Page


Reply

4 Posts   33188 Views

Avatar
Garrett

24 June 2008 at 2:48am Community Member, 245 Posts

Hi,

How in Silverstripe do you enable multiple editable areas on single page?? This "$Content" variable seems to represent ALL the dynamic content in the template. This cannot be true! I tried including another template in order to separate them in the CMS and this doesn't work either as "$Content" assumes the same value since both instances occur int he same page. How can I have MULTIPLE instances of "$Content"??? Help!

Thanks,
Garrett

Avatar
Double-A-Ron

24 June 2008 at 9:03am Community Member, 604 Posts

If I am understanding what you are after correctly, you need to create a new HTMLEditorField for your page type in the getCMSFields() method. Like so:

function getCMSFields() {
$fields = parent::getCMSFields();

$fields->addFieldToTab('Root.Content.Main', new HTMLEditorField('MyField', 'Label for my field'), 'Content'); // The last argument will place your new field above Content.

return $fields;
}

If you no longer need the main Content field, you can remove it by adding $fields->removeFieldFromTab("Root.Content.Main","Content"); in that method before the return $fields; line.

Cheers
Aaron

Avatar
Willr

24 June 2008 at 10:59am Forum Moderator, 5511 Posts

Have a read of the second tutorial - this covers adding extra fields to pages. Basically to add on to what aaron said, theres 3 steps

1 - Add the field to the Database

Open up mysite/code/Page.php and in the static $db = array() add a field with the type HTML Text. So it would look something like below. After you add this run yoursite.com/db/build?flush=1 to rebuild the database.

static $db = array(
'SecondContent' => 'HTMLText'
// insert extra fields here
);

2. Add the field to the CMS so you can write content! - Just as per the last post

// Add this method under your static $db array bit.
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', new HTMLEditorField('SecondContent', 'Second Content'));

return $fields;
}

3. And last step is to add the variable $SecondContent to wherever you want to render the content in the template!

Avatar
Double-A-Ron

24 June 2008 at 11:06am Community Member, 604 Posts

Open up mysite/code/Page.php and in the static $db = array() add a field with the type HTML Text.

static $db = array(
'SecondContent' => 'HTMLText'
// insert extra fields here
);

Oops, yes forgot that step. It's a must.