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.

Archive /

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

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

HomePage.ss not working


Reply


7 Posts   1762 Views

Avatar
Servicefly

Community Member, 8 Posts

25 September 2008 at 11:20pm

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?

Avatar
Hamish

Community Member, 712 Posts

26 September 2008 at 10:03am

Edited: 26/09/2008 10:05am

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!

Avatar
Servicefly

Community Member, 8 Posts

29 September 2008 at 3:04am

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

Avatar
Servicefly

Community Member, 8 Posts

29 September 2008 at 3:14am

Edited: 29/09/2008 3:15am

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

Avatar
Servicefly

Community Member, 8 Posts

29 September 2008 at 3:17pm

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?

Avatar
Hamish

Community Member, 712 Posts

30 September 2008 at 9:03am

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

Avatar
Servicefly

Community Member, 8 Posts

30 September 2008 at 6:48pm

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.