Jump to:

5552 Posts in 1742 Topics by 1226 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Multi-column home-page.

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

Page: 1
Go to End
Author Topic: 1613 Views
  • COGO
    Avatar
    Community Member
    4 Posts

    Multi-column home-page. Link to this post

    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?

  • Willr
    Avatar
    Forum Moderator
    5511 Posts

    Re: Multi-column home-page. Link to this post

    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'));
    }

  • COGO
    Avatar
    Community Member
    4 Posts

    Re: Multi-column home-page. Link to this post

    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 {

    }
    ?>

  • Willr
    Avatar
    Forum Moderator
    5511 Posts

    Re: Multi-column home-page. Link to this post

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

  • COGO
    Avatar
    Community Member
    4 Posts

    Re: Multi-column home-page. Link to this post

    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

  • Mo
    Avatar
    Community Member
    508 Posts

    Re: Multi-column home-page. Link to this post

    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();
       }
    }

  • Mo
    Avatar
    Community Member
    508 Posts

    Re: Multi-column home-page. Link to this post

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

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