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.

Customising the CMS /

Multi-column home-page.


Reply


7 Posts   1662 Views

Avatar
COGO

Community Member, 4 Posts

31 August 2009 at 3:54am

Hi, I'm wondering if anyone can help.

I've downloaded silverstripe and putting together a simple CMS for a client (a good way of testing it). Currently I think it's really good, but I'm a little stuck at trying to create a multi-column layout for the home-page.

I have Page.css which holds the main theme, which is split into subtemplates /Layout/ Page.ss and HomePage.ss

I also have a mysite/code/HomePage.php - which is where I'm struggling. Getting that working was fine, but trying to add in a multi-column layout for home is being a bit of a pita.

In home, I currently have:

<?php
/**
* Defines the HomePage page type
*/

class HomePage extends Page {
static $db = array(
      'ColumnOne' => 'HTMLText',
      'ColumnTwo' => 'HTMLText'
);
static $has_one = array(
      $fields->addFieldToTab("Root.Content.ColumnOne", new HTMLEditorField('ColumnOne','Column One Content'));
      $fields->addFieldToTab("Root.Content.ColumnTwo", new HTMLEditorField('ColumnTwo','Column Two Content'));
);

}

class HomePage_Controller extends Page_Controller {
   
}
?>

But is giving the error:
Parse error: parse error, expecting `')'' in D:\clients\cogocreative\domains\dev.silverstripe\mysite\code\HomePage.php on line 12

Does anyone know what I'm doing wrong?

Avatar
Willr

Forum Moderator, 5513 Posts

31 August 2009 at 9:08am

You have got cms fields in your database schema. Your $has_one should actually be a getCMSFields()

// remove your $has_one

function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.ColumnOne", new HTMLEditorField('ColumnOne','Column One Content'));
$fields->addFieldToTab("Root.Content.ColumnTwo", new HTMLEditorField('ColumnTwo','Column Two Content'));
}

Avatar
COGO

Community Member, 4 Posts

1 September 2009 at 11:54pm

Still no luck :(

I've got this now

<?php
/**
* Defines the HomePage page type
*/

class HomePage extends Page {
static $db = array(
'ColumnOne' => 'HTMLText',
'ColumnTwo' => 'HTMLText'
);
function getCMSFields() {
$fields = parent::getCMSFields();
    $fields->addFieldToTab("Root.Content.ColumnOne", new HTMLEditorField('ColumnOne','Column One Content'));
$fields->addFieldToTab("Root.Content.ColumnTwo", new HTMLEditorField('ColumnTwo','Column Two Content'));

}

class HomePage_Controller extends Page_Controller {

}
?>

Avatar
Willr

Forum Moderator, 5513 Posts

2 September 2009 at 10:03am

woops I forgot to add the return $fields; to the function.

function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.ColumnOne", new HTMLEditorField('ColumnOne','Column One Content'));
$fields->addFieldToTab("Root.Content.ColumnTwo", new HTMLEditorField('ColumnTwo','Column Two Content'));
return $fields;
}

Avatar
COGO

Community Member, 4 Posts

2 September 2009 at 10:14am

Lol, ok now I got

<?php
/**
* Defines the HomePage page type
*/

class HomePage extends Page {
static $db = array(
'ColumnOne' => 'HTMLText',
'ColumnTwo' => 'HTMLText'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.ColumnOne", new HTMLEditorField('ColumnOne','Column One Content'));
$fields->addFieldToTab("Root.Content.ColumnTwo", new HTMLEditorField('ColumnTwo','Column Two Content'));
return $fields;
}

class HomePage_Controller extends Page_Controller {

}
?>

And I'm getting:
Parse error: syntax error, unexpected T_CLASS, expecting T_FUNCTION in D:\clients\cogocreative\domains\dev.silverstripe\mysite\code\HomePage.php on line 18

I'm wondering if I've set-out /mysite/code/HomePage.php wrong or I'm missing something.

Would be good to get it live, then change the theme a little and release it here. The theme section seems to be lacking a little :)

Avatar
Mo

Community Member, 510 Posts

10 September 2009 at 4:59am

Edited: 10/09/2009 4:59am

Aren't you meant to autoload your controller?

I think your controller should be:

class HomePage_Controller extends Page_Controller {
   public function init() {
      parent::init();
   }
}

Avatar
Mo

Community Member, 510 Posts

10 September 2009 at 5:00am

Also, have you re-run /dev/build/ and flushed your homepage template?