I have a TestimonalHolder
page type that has Testimonials
page type as its children which each have a Message
$db field to store a testimonal.
Question is how do I access that $Message
field on my HomePage.ss
for example so I can loop through them and will put them into a slider etc.
Testimonials.php
class Testimonials extends Page {
private static $db = array(
'Message' => 'Text'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldsToTab('Root.Testimonials', array(
TextareaField::create('Message')
));
return $fields;
}
}
class Testimonials_Controller extends Page_Controller {
}
I know I can loop through them by using this code on my TestimonialHolder.ss
page:
<% loop $Children %>
<h2>$Title</h2>
$Message
<% end_loop %>
In your HomePage.php
public function getTestimonials($limit = 5) {
return Testimonials::get()->limit($limit);
}
Then in your template, just use $Testimonials
like you would $Children
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With