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.

Archive /

Our old forums are still available as a read-only archive.

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

Let's Just Pretend That I'm A Moron...


Go to End


14 Posts   6875 Views

Avatar
revstevens

Community Member, 9 Posts

8 September 2008 at 8:47am

Edited: 08/09/2008 9:24am

That isn't really very hard to do, so it seems like a good place to start.

Let me start by saying that I know HTML and CSS. However, I don't know jack about PHP.

I'm trying to find a good CMS that can be implemented in future projects and like the interface that SS has to offer. I thought the best place to start would be on my own site, which I developed in Dreamweaver, and am building the template for in SS.

*EDITED FROM HERE ON

I actually just came to a realization that, really, I need 3 separate editable areas.

1. main content
2. side content
3. Another area below the main content that shows a list of recent work

I have all the styles defined, but how do I actually create more than one editable area in the CMS?

Avatar
Willr

Forum Moderator, 5523 Posts

8 September 2008 at 3:26pm

Its pretty simple and Im it should be on the wiki but I cant find it! So i might write this up on there for future reference as well but here it goes. You need 3 steps

Step 1. Add the 2 New Areas to your database

Open up mysite/code/Page.php in your text editor and add these 2 entries inside the static $db = array(); bit

'SidebarContent' => 'HTMLText' , 'RecentWorkContent' => 'HTMLText'

Step 2. Add the 2 New Areas to your CMS editor

In that same file you should see a function getCMSFields() function. You need to use this to add 2 fields to the CMS

function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Main", new HTMLEditorField("SidebarContent"));
$fields->addFieldToTab("Root.Content.Main", new HTMLEditorField("RecentWorkContent"));
return $fields;
}

Now you just need to rebuild your sites database by visiting http://yoursite.com/db/build?flush=1 and then view the admin section to make sure your fields have been added! But you have 1 more step! You need to see it from the front end.

Step 3. Tell the template where to output these to

Open up a template file - which ever one you want to output the content too, For this say themes/blackcandy/templates/Layout/Page.ss and add the 2 fields

$SidebarContent
.. 
$RecentWorkContent

Avatar
revstevens

Community Member, 9 Posts

14 September 2008 at 5:13am

OK, if this works, I'm going to love you forever, in a mostly straight way.
I'll be trying it out in a bit and I'll let you know if I manage to foul things up at all.

Thanks again.

Avatar
revstevens

Community Member, 9 Posts

15 September 2008 at 4:55am

Edited: 15/09/2008 4:56am

Alright, I put the info into the page.php file, which now looks like this:

<?php

class Page extends SiteTree {
	static $db = array(
	'ContentSub' => 'HTMLText' , 'RecentWork' => 'HTMLText'
	);
	
	static $defaults = array(
	);

	function getCMSFields() {
	$fields = parent::getCMSFields();
	$fields->addFieldToTab("Root.Content.Main", new HTMLEditorField("ContentSub"));
	$fields->addFieldToTab("Root.Content.Main", new HTMLEditorField("RecentWork"));
	return $fields;
}

class Page_Controller extends ContentController {
	function init() {
		parent::init();
		
		Requirements::themedCSS("layout");
		Requirements::themedCSS("typography");
		Requirements::themedCSS("colors");
	}
}

?>

Let me know if there is a problem there, because, after I do that I flush the database, but it doesn't flush very far. It only goes to here:

Building Database

Creating database tables

Newsletter
Newsletter_SentRecipient
Newsletter_Recipient
NewsletterType
PageComment
Email_BounceRecord
Email_BlackList
PageView
SiteTree
QueuedEmail
File
EditableCheckboxOption
EditableDropdownOption
EditableFormField
EditableRadioOption
SubmittedForm
SubmittedFormField
Group
Member
Member_UnsubscribeRecord
Permission
Widget
WidgetArea
GhostPage

What am I doing wrong here? Cause I know this is my fault.

Avatar
bennybtl

Community Member, 12 Posts

16 September 2008 at 5:46am

Edited: 16/09/2008 5:47am

*edited*

Avatar
revstevens

Community Member, 9 Posts

17 September 2008 at 12:24pm

Help?

Avatar
Hamish

Community Member, 712 Posts

17 September 2008 at 5:46pm

"Oh my god, it's a ghost page!"

Try generating the database from scratch - ie, drop the current database, or change the database in your _config.php and see if it will generate a new database correctly.

I have experienced issues where it will get hung up changing existing tables and the quickest solution has been to drop and rebuild.

Of course, if you already have lots of content in your database, you might not want to do that, but if you rename the old database and rebuild it, it would only take a bit of SQL to pull your data back across.

Other than that, your code should work. If the actions above don't solve the issue, post back and I'll set up your code and see what happens.

Avatar
revstevens

Community Member, 9 Posts

19 September 2008 at 12:07am

I'll try. I'm not much of a back-end code editor, but I think I can figure it out. It may take me a few days to get back to you and let you know how it went, so please don't think I've given up. I appreciate the help.

Go to Top