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.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

How to create a full homepages as demo


Reply

2 Posts   496 Views

Avatar
makensy13

19 March 2011 at 9:04am Community Member, 2 Posts

Hello,

My question is:

How to create homepages (as in the demo):

- Content
- Left box text
- Left Image
- Middle text box
- Middle Image
- Right text box
- Image Right

Thank you again

Sincerely,

Avatar
Willr

19 March 2011 at 6:11pm Forum Moderator, 5511 Posts

Have a read of tutorial 2. This covers how to add fields to pages. In the case of the demo it looks something like

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

class HomePage_Controller extends Page_Controller {

}

But I recommend reading the 2nd SilverStripe tutorial (http://doc.silverstripe.org/sapphire/en/tutorials/2-extending-a-basic-site) to get to grips with what that code does.