Hey guys,
Relativley new to SS, I've read "Silverstripe: The complete guide to CMS development" and I'm adapting the Jobs module that I've created whilst reading the book.
I basically want to access the "Jobs" DataObject from my "HomePage" class so that I can show the latest 5 jobs on the home page. Here's whats going on in my HomePage.php
<?php
class HomePage extends Page {
public static $db = array(
);
static $has_many = array(
'Jobs' => 'Job',
);
}
class HomePage_Controller extends Page_Controller {
function LastestJobs() {
return DataObject::get("Jobs");
}
}
?>
So I'm assuming that in order to access the contents of the "Jobs" DataObject I need to first create a one-to-many relationship between my "HomePage" class and the "Jobs" DataObject since the home page can list many (well up to 5) jobs and any one job will only be listed on the home page once.
Heres the relevent code in HomePage.ss
<ul>
<% control LatestJobs %>
<li class="job" id="Job{$ID}">
<h3><a href="$Link">$Title</a></h3>
<p class="description">Description: $Description</p>
</li>
<% end_control %>
</ul>
When I view the page, I'm seeing a single loop over the markup inside the control block with blank spaces where all of the data from the the variables should be. What am I doing wrong?
Apologies if I'm making a really noob mistake here, I've spent the whole day trying to find an anwser myself. Fail :(
-Robbie