Jump to:

520 Posts in 248 Topics by 263 members

Content Editor Discussions

SilverStripe Forums » Content Editor Discussions » Demo CMS template layout

Forum for content editors and CMS users.

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

Page: 1
Go to End
Author Topic: 1594 Views
  • Mavic
    Avatar
    Community Member
    5 Posts

    Demo CMS template layout Link to this post

    Hi Guys,

    How do I set up a page in the CMS like the CMS demo home page with four separate content areas each one editable in the CMS?

    There will obviously need to be some template changes to accommodate this too.

    Cheers Jeff

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: Demo CMS template layout Link to this post

    Have a read of tutorial 2 for an explanation on how to add fields to the cms and templates. The PHP code for demo looks something like this for reference

    <?php

    class HomePage extends Page {
       static $db = array(
          "LeftBoxTxt" => "HTMLText",
          "MiddleBoxTxt" => "HTMLText",      
          "RightBoxTxt" => "HTMLText"
    );

       static $has_one = array(
          'LeftBoxImg' => 'Image',
          'MiddleBoxImg' => 'Image',
          'RightBoxImg' => 'Image'
    );
       
       function getCMSFields() {
          $fields = parent::getCMSFields();
          
          $fields->addFieldToTab("Root.Content.Main", new HTMLEditorField("LeftBoxTxt","Left box text"));
          $fields->addFieldToTab("Root.Content.Main", new ImageField('LeftBoxImg', 'Left Image'));
          
          $fields->addFieldToTab("Root.Content.Main", new HTMLEditorField('MiddleBoxTxt','Middle box text'));
          $fields->addFieldToTab("Root.Content.Main", new ImageField('MiddleBoxImg', 'Middle Image'));
          
          $fields->addFieldToTab("Root.Content.Main", new HTMLEditorField('RightBoxTxt','Right box text'));
          $fields->addFieldToTab("Root.Content.Main", new ImageField('RightBoxImg', 'Right Image'));
          
          return $fields;
       }

       // ....

    And then in the template just standard $RightBoxTxt etc for each element. If your new to SilverStripe that above code will look overwhelming so I encourage you read the tutorial first.

  • Mavic
    Avatar
    Community Member
    5 Posts

    Re: Demo CMS template layout Link to this post

    Hey Willr,

    Thanks very much for this, I'm OK with the PHP, but I am new to SilverStripe and keen to develop some templates.

    This info is perfect and will get me going in the right direction.

    Cheers Jeff

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