Greetings,
Just starting out SS v2.4.3, trying to implement a LatestNews function within HomePage_Controller which will allow me to pull both "news" and "announcements" (both which use ArticleHolder/ArticlePage pages). The ArticleHolders and ArticlePages all display correctly. The HomePage summary displays a single empty object each for News and Annoucements.
I've tried more than a few dozen subtle permutations based on various forum articles and reading the DataObject documentation. Here's where I'm at:
class HomePage_Controller extends Page_Controller {
function LatestNews($title='news', $num=5) {
$mynews = DataObject::get("ArticleHolder", "URLSegment = '". $title . "'");
if (!$mynews || !$mynews->exists()) {
echo "fail";
return false;
}
return ($items) ? DataObject::get("ArticlePage", "ParentID = ". $mynews->ID, "ArticleDate DESC", "", $num) : false;
}
}
In the HomePage.ss layout is the following:
<h2>Announcements</h2>
<ul id="NewsList">
<% control LatestNews(announcements) %>
<li class="newsDateTitle"><a href="$Link" title="Read more on "{$Title}"">$Title</a></li>
<li class="newsDateTitle">$ArticleDate.Nice</li>
<li class="newsSummary">$Content.FirstParagraph<a href="$Link" title="Read more on "{$Title}"">Read more >></a></li>
<% end_control %>
</ul>
<h2>Latest News</h2>
<ul id="NewsList">
<% control LatestNews(news) %>
<li class="newsDateTitle"><a href="$Link" title="Read more on "{$Title}"">$Title</a></li>
<li class="newsDateTitle">$ArticleDate.Nice</li>
<li class="newsSummary">$Content.FirstParagraph<a href="$Link" title="Read more on "{$Title}"">Read more >></a></li>
<% end_control %>
</ul>
Not surprisingly, an example of the resulting HTML is:
<h2>Latest News</h2>
<ul id="NewsList">
<li class="newsDateTitle"><a href="" title="Read more on """></a></li>
<li class="newsDateTitle"></li>
<li class="newsSummary"><a href="" title="Read more on """>Read more >></a></li>
</ul>
I've spent about 8 hours on this; I'm sure its a classic blunder, and I'll really appreciate any help!
Bret