Remember me? forgot password | register

SilverStripe Forum

4682 Posts in 1048 Topics by 664 members

Jump to:

Extending and hacking

If this is your first visit, you will need to register before you can post. However, you can browse all messages below.

Community » SilverStripe Forum » Extending and hacking » Homepage page listing
Page: 1 , 2 go to end Reply
Author Topic: Homepage page listing 1245 views
  • galilee
    avatar
    Community Member
    28 posts
    8 SilverStripe Sites

    Homepage page listing Link to this post

    Hi, I'm pretty new to this and having some trouble implementing a function on the homepage which lists pages from another section. I've got the news list sorted from the tutorials but can't seem to replicate it ... and trying to find documentation is a nightmare!

    I've got a DocumentHolder type and a DocumentPage type:


    *** in DocumentHolder.php ***

    class DocumentHolder extends Page {   
       static $db = array();   
       static $has_one = array();
    static $allowed_children = array('DocumentPage');
    }

    class DocumentHolder_Controller extends Page_Controller {}

    *** in DocumentPage.php ***

    class DocumentPage extends Page {
    static $db = array(
    'PDFdocDesc' => 'Text',
    'ShowOnHomePage' => 'Text'
    );
    static $has_one = array(
    'PDFdoc' => 'File'
    );
       
    function getCMSFields() {
       $fields = parent::getCMSFields();
       $fields->addFieldToTab("Root.Content.Main", new TextField('PDFdocDesc',"Document Description"));
       $fields->addFieldToTab("Root.Content.Main", new FileIFrameField('PDFdoc',"PDF Document"));    
          $fields->addFieldToTab("Root.Content.Main", new CheckboxField('ShowOnHomePage',"Show this on homepage?"));    
          $fields->removeFieldFromTab("Root.Content.Main", "Content");
                
    return $fields;
    }
    }

    class DocumentPage_Controller extends Page_Controller {
       
    }

    and, I'm pretty sure this is where I'm getting trouble because I just copied the news one & I don't fully understand it yet :)

    class HomePage extends SiteTree {
       static $db = array(
       'SubTitle' => 'Text'
       );
       static $has_one = array(
    );

    class HomePage_Controller extends ContentController {
       function init() {
          parent::init();
          
          }
          
       function LatestNews($num=5) {
       $news = DataObject::get_one("NewsIntroPage");
       return ($news) ? DataObject::get("NewsArticlePage", "ParentID = $news->ID", "Date DESC", "", $num) : false;
    }

       function HomeDocs($num=5) {
        $doccys = DataObject::get_one("DocumentHolder");
        return ($doccys) ? DataObject::get("DocumentPage", "ParentID = $doccys->ID", "Date DESC", "", $num) : false;
    }
    }

    In my sidebar I'm trying to do this:


    <% control HomeDocs %>
           <% if $ShowOnHomePage %>   
    <li ><a href="$PDFdoc.filename" target="_blank" title="Download this file">$Title t</a></li>
          <% end_if %>
       <% end_control %>

    any help with this would be much appreciated. Thanks

    Last edited: 14 June 2008 at 5:42pm

  • Double-A-Ron
    avatar
    Community Member
    149 posts
    1 SilverStripe Site

    Re: Homepage page listing Link to this post

    What error/problem are you experiencing exactly?

  • Double-A-Ron
    avatar
    Community Member
    149 posts
    1 SilverStripe Site

    Re: Homepage page listing Link to this post


    class HomePage_Controller extends ContentController {

    Can you post the code you have for the HomePage class? I haven't been through this tutorial but I think that line should be:

    class HomePage_Controller extends PageController {

    Cheers
    Aaron

  • galilee
    avatar
    Community Member
    28 posts
    8 SilverStripe Sites

    Re: Homepage page listing Link to this post

    Hi Aaron...I've added my Homepage class in the code above. Homepage sits at the same level as page (doesn't inherit from it) so extends sitetree rather than page.

  • Double-A-Ron
    avatar
    Community Member
    149 posts
    1 SilverStripe Site

    Re: Homepage page listing Link to this post

    So what is happening when you run that code exactly? It helps to know the error and where the error is occurring.

    Aaron

  • galilee
    avatar
    Community Member
    28 posts
    8 SilverStripe Sites

    Re: Homepage page listing Link to this post

    sorry....so if I try and include the HomeDocs function on my homepage all I get when I try to go to the site is a blank page with:

    Error
    The website server has not been able to respond to your request.

  • dio5
    avatar
    Community Member
    401 posts
    8 SilverStripe Sites

    Re: Homepage page listing Link to this post

    try

    class HomePage_Controller extends Page_Controller {

    with an underscore between page and controller...

    *** edit ** sorry I didn't read everything, so just ignore this :)

    Last edited: 14 June 2008 at 8:58pm

  • willr
    avatar
    Core Development Team
    1263 posts
    3 SilverStripe Sites 2 SilverStripe Themes

    Re: Homepage page listing Link to this post

    Put your site into dev mode so you can actually see the proper error rather then that blank generic one. So open up mysite/_config.php and add

    Director::set_environment_type("dev");

    or if you are doing this on a local dev environment eg WAMP or MAMP then make sure your server is in the array of dev servers in that _config

    Director::set_dev_servers(array(
       'localhost',
       '127.0.0.1',
    ));

    Once the sites in dev mode we shall see a bright red (sometimes helpful) error!.

    1245 views
go to top Reply

Currently Online:

bebabeba, Invader_Zim, joon, Matt Hardwick

Welcome to our latest member: Boomer T