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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

How to create a full homepages as demo


Go to End


2 Posts   995 Views

Avatar
makensy13

Community Member, 2 Posts

19 March 2011 at 9:04am

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

Forum Moderator, 5523 Posts

19 March 2011 at 6:11pm

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.