Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » HomePage.ss not working

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

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

Page: 1
Go to End
Author Topic: 1702 Views
  • Servicefly
    Avatar
    Community Member
    8 Posts

    HomePage.ss not working Link to this post

    Alright I have scoured the forum and documentation about my problem to avail. I have created the HomePage.php file in /mysite/code folder then created the HomePage.ss file in /mysite/template folder. I have no files in the /tutorial/ area of the website and the config.php points to /mysite/ as the theme directory.

    I renamed the Page.ss to allow the HomePage.ss to be picked up by the CMS. Both files currently have identical code. Page.ss worked great before the temporary rename. I have double checked the HomePage.php code with the tutorial on the SilverStripe website here and it matches; I even tried variations just in case. No "HomePage" type exists in the "create" drop down after db build and flush. Could I be overlooking anything in the code or missing a controller convention?

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: HomePage.ss not working Link to this post

    If it's not showing up in the CMS drop down for creating a page, it's not the template that is the problem.

    Could you post the code for HomePage.php? At the bare minimum it should look like this:

    class HomePage extends Page {

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

    EDIT: wtf is up with forum code styling? BBCodeParser strikes again!

  • Servicefly
    Avatar
    Community Member
    8 Posts

    Re: HomePage.ss not working Link to this post

    Here is the HomePage.php code:

    <?php

    class HomePage extends SiteTree {
       static $db = array(
       );
       static $has_one = array(
    "Sidebar" => "WidgetArea",
    );

    function getCMSFields() {
       $fields = parent::getCMSFields();
       $fields->addFieldToTab("Root.Content.Widgets", new WidgetAreaEditor("Sidebar"));
       return $fields;
    }
    }

    class HomePage_Controller extends Page_Controller {
       function init() {
          parent::init();
          
          Requirements::themedCSS("layout");
          Requirements::themedCSS("typography");
          Requirements::themedCSS("form");
       }
    function SearchForm() {
    $searchText = isset($this->Query) ? $this->Query : 'Search';
          
    $fields = new FieldSet(
    new TextField("Search", "", $searchText)
    );

    $actions = new FieldSet(
    new FormAction('results', 'Go')
    );

    return new SearchForm($this, "SearchForm", $fields, $actions);
    }
    function results($data, $form){
    $data = array(
    'Results' => $form->getResults(),
    'Query' => $form->getSearchQuery(),
    'Title' => 'Search Results'
    );
       
    return $this->customise($data)->renderWith(array('Page_results', 'Page'));
    }
    function LatestNews($num=5) {
    $news = DataObject::get_one("ArticleHolder");
    return ($news) ? DataObject::get("ArticlePage", "ParentID = $news->ID", "Date DESC", "", $num) : false;
    }
    }
    ?>

  • Servicefly
    Avatar
    Community Member
    8 Posts

    Re: HomePage.ss not working Link to this post

    I posted the wrong code, sorry moderators. Here is the right code:

    <?php

    class HomePage extends Page {
       static $db = array(
       );
       static $has_one = array(
    "Sidebar" => "WidgetArea",
    );

    function getCMSFields() {
       $fields = parent::getCMSFields();
       $fields->addFieldToTab("Root.Content.Widgets", new WidgetAreaEditor("Sidebar"));
       return $fields;
    }
    }

    class HomePage_Controller extends Page_Controller {
       function init() {
          parent::init();
          
          Requirements::themedCSS("layout");
          Requirements::themedCSS("typography");
          Requirements::themedCSS("form");
       }
    function SearchForm() {
    $searchText = isset($this->Query) ? $this->Query : 'Search';
          
    $fields = new FieldSet(
    new TextField("Search", "", $searchText)
    );

    $actions = new FieldSet(
    new FormAction('results', 'Go')
    );

    return new SearchForm($this, "SearchForm", $fields, $actions);
    }
    function results($data, $form){
    $data = array(
    'Results' => $form->getResults(),
    'Query' => $form->getSearchQuery(),
    'Title' => 'Search Results'
    );
       
    return $this->customise($data)->renderWith(array('Page_results', 'Page'));
    }
    function LatestNews($num=5) {
    $news = DataObject::get_one("ArticleHolder");
    return ($news) ? DataObject::get("ArticlePage", "ParentID = $news->ID", "Date DESC", "", $num) : false;
    }
    }
    ?>

  • Servicefly
    Avatar
    Community Member
    8 Posts

    Re: HomePage.ss not working Link to this post

    I used the developer code line in the _config.php:
    Director::set_environment_type("dev");

    to get the db build and flush.

    Now I have the HomePage wrapping around itself. Any idea what is going on?

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: HomePage.ss not working Link to this post

    Hi,

    You said before that 'No "HomePage" type exists in the "create" drop down after db build and flush'. Is that fixed now? You last post implies that you've managed to create a HomePage page but it is now displaying incorrectly.

    If so, maybe you've got the template file sitting in the wrong folder (ie, a full page template inside the Layout folder).

  • Servicefly
    Avatar
    Community Member
    8 Posts

    Re: HomePage.ss not working Link to this post

    Hamish,

    Thanks for your to help. Once I used the developer mode code in _config.php I found from Willr's other post, I was able to do the db buil and flush I could not do previously. Then you reminded me to check the /layout/ directory (DUH!) and I found exact duplicates of both the HomePage.ss and Page.ss. Still not sure how they got there; probably a late night/early morning developing session.

    ALL IS FIXED, thanks again for your replies. If I can help in the future I will look out for your posts.

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