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.

Template Questions /

[solved] Latest News not shown on the homepage


Reply


6 Posts   2311 Views

Avatar
clauer

Community Member, 12 Posts

17 January 2009 at 11:48am

Edited: 19/01/2009 4:36am

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

Avatar
Liam

Community Member, 470 Posts

18 January 2009 at 8:26am

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?

Avatar
clauer

Community Member, 12 Posts

18 January 2009 at 10:29am

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

Avatar
Willr

Forum Moderator, 5513 Posts

18 January 2009 at 10:13pm

Edited: 18/01/2009 10:14pm

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

Avatar
clauer

Community Member, 12 Posts

19 January 2009 at 4:31am

Edited: 19/01/2009 4:36am

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

Avatar
derpixler

Community Member, 4 Posts

22 January 2009 at 9:19am

Edited: 22/01/2009 9:20am

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.