Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Multiple Editable Areas on a Single Page

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: 33072 Views
  • Garrett
    Avatar
    Community Member
    245 Posts

    Multiple Editable Areas on a Single Page Link to this post

    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

  • Double-A-Ron
    Avatar
    Community Member
    599 Posts

    Re: Multiple Editable Areas on a Single Page Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Multiple Editable Areas on a Single Page Link to this post

    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!

  • Double-A-Ron
    Avatar
    Community Member
    599 Posts

    Re: Multiple Editable Areas on a Single Page Link to this post

    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.

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