Jump to:

3397 Posts in 978 Topics by 854 members

Template Questions

SilverStripe Forums » Template Questions » [solved] Latest News not shown on the homepage

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

Page: 1
Go to End
Author Topic: 2094 Views
  • clauer
    Avatar
    Community Member
    12 Posts

    [solved] Latest News not shown on the homepage Link to this post

    Hi,

    according to tut #2 I prepared the controller of homepage.php to get the latest news from the news pages.

    As long as I can show them on the NewsHolder page even sorted by date, I do not see them on the homepage. Here is the piece of code:

    <div id="col2">
       <div id="col2_content" class="clearfix">
          <ul id="NewsList">
             <% control LatestNews %>
                <li class="newsDateTitle"><a href="$Link" title=""($Title)%quot;">$Title</a></li>
                <li class="newsDateTitle">$Date.Format(j. M. Y) von $Author</li>
                <li class="newsSummary">$Content.FirstParagraph <a href="$Link" title="mehr...">mehr...</a></li>
             <% end_control %>
          </ul>
       </div>
    </div>

    btw, other contents are shown in <div id="col2">

    The function named "LatestNews" is defined in the controller class of the homepage.

    Any ideas? Thanks in advance.

    Christian

  • Liam
    Avatar
    Community Member
    470 Posts

    Re: [solved] Latest News not shown on the homepage Link to this post

    Have you flushed your template? ?flush=1?

    So you have the function in the homepage.php controller. Do you use $Layout to setup a specific template for HomePage? Where is this html code going?

    What content is being shown instead?

  • clauer
    Avatar
    Community Member
    12 Posts

    Re: [solved] Latest News not shown on the homepage Link to this post

    Hi LeeUmm,

    thanks for your answer.

    Yes, I did flush the template as well as rebuilding the database.

    In page.ss, I use $Layout:

    /********************** code snippet
                <!-- begin: main content area #main -->
                <div id="main">
                   $Layout
                </div>
                <!-- end: #main -->
    end code snippet ************************/

    Then I wrote the template HomePage.ss which is ok in all parts except in not showing the newslist (I've set up a 3-col layout based on the css-framework YAML, col2 is the one on the right side. The framework is fine for all parts of the site there are no problems at all).

    /********************** HomePage.css
    <!-- begin: #col1 - first float column -->
    <% include LeftColumn %>
    <!-- end: #col1 -->

    <!-- begin: #col2 second float column -->
    <!-- <% include RightColumn %> -->
    <div id="col2">
       <div id="col2_content" class="clearfix">
          <ul id="NewsList">
             <% control LatestNews %>
                <li class="newsDateTitle"><a href="$Link" title="&quot;($Title)%quot;">$Title</a></li>
                <li class="newsDateTitle">$Date.Format(j. M. Y) von $Author</li>
                <li class="newsSummary">$Content.FirstParagraph <a href="$Link" title="mehr...">mehr...</a></li>
             <% end_control %>
          </ul>
       </div>
    </div>
    <!-- end: #col2 -->

    <!-- begin: #col3 static column -->
    <div id="col3">
       <div id="col3_content" class="clearfix"> <a id="content" name="content"></a>
          <div id="Banner">
             <img src="mysite/images/welcome.png" alt="Homepage image" />
          </div>
          $Content
       </div>
    <div id="ie_clearing">&nbsp;</div>
    <!-- End: IE Column Clearing -->
    <!-- end: #col3 -->
    end HomePage,css ************************/

    While the content of col1 and col3 is shown correctly, the content of col3 is not. If I replace the current template of col2 by another template, the content the new template produces is shown.

    And this is the html code generated:

    /********************** code snippet
    <!-- begin: #col2 second float column -->
    <div id="col2">
       <div id="col2_content" class="clearfix">
          <ul id="NewsList">
             
          </ul>
       </div>
    </div>
    <!-- end: #col2 -->
    end of code snippet ************************/

    As you can see the control seems to not return a value so no content is beeing displayed.

    The site is in dev-mode but I don't get any errors.

    To complete all pieces of code, here's the controller of the HomePage.

    /********************** code snippet
    class HomePage_Controller extends Page_Controller {
       function LatestNews($num=5) {
          $news = DataObject::get_one("NewsHolder");
          return ($news) ? DataObject::get("NewsPage", "ParentID = '$news->id'", "Date DESC", "", $num) : false;
          }
       }   
    end code snippet ************************/

    How can I debug the result of the function LatestNews? Seems that it is false?

    Thanks for your assistance.
    Christian

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: [solved] Latest News not shown on the homepage Link to this post

    Christan - as a note you can use [ code ] [/ code ] (without spaces) to mark code snippets up. No need for the ***.

    As for debugging your code you can use Debug::show() to show values of a DataObject or any SilverStripe class.

    class HomePage_Controller extends Page_Controller {
    function LatestNews($num=5) {
    $news = DataObject::get_one("NewsHolder");
    Debug::show($news);
    return ($news) ? DataObject::get("NewsPage", "ParentID = '$news->id'", "Date DESC", "", $num) : false;
    }
    }

  • clauer
    Avatar
    Community Member
    12 Posts

    Re: [solved] Latest News not shown on the homepage Link to this post

    Thanks for your tipps. I did the debugging as suggested and it returned the record's content of the NewsHolder page. But the statement:

    return ($news) ? DataObject::get("NewsPage", "ParentID = '$news->id'", "Date DESC", "", $num) : false;


    didn't return anyhing at all.

    So I had another closer look at the statement and changed it to this one

    return ($news) ? DataObject::get('NewsPage', 'ParentID = ' . $news->id, 'Date DESC', '', $num) : false;

    So simply exchanging the " by ' solved the problem. It's just a bug in tutorial 2...
    Christian

  • derpixler
    Avatar
    Community Member
    4 Posts

    Re: [solved] Latest News not shown on the homepage Link to this post

    Hi i've a simliar Problem,

    in my Sitetree i've this structure:
    Home Page
    ..........|_ ArtikelHolder1
    ..............................|_ ArtikelHolder2
    ............................................|_ ArtikelHolder3
    ........................................................|_ Newspage
    ........................................................|_ Newspage
    ........................................................|_ Newspage
    ........................................................|_ Newspage

    with the same code form clauer : $doSet = DataObject::get_one("ArtikelHolder1", "`ParentID` = '".$this->ID."'", "", "");
    so i get only the first children of ArtikelHolder1 but i'll show all Newspages on every ArtikelHolder.

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