17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 32882 Views |
-
Multiple Editable Areas on a Single Page

24 June 2008 at 2:48am
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 -
Re: Multiple Editable Areas on a Single Page

24 June 2008 at 9:03am
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 -
Re: Multiple Editable Areas on a Single Page

24 June 2008 at 10:59am
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!
-
Re: Multiple Editable Areas on a Single Page

24 June 2008 at 11:06am
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.
| 32882 Views | ||
|
Page:
1
|
Go to Top |



