Hi
I have set up a data object of testimonials that I want to display on the homepage of my site.
I've set it up so I add my testimonials on a testimonials tab when editing the homepage. It all seems to work fine, but I am having trouble displaying them through a control loop.
Quote.php
<?php
/**
* Defines the Quote data object
*/
class Quote extends DataObject {
static $db = array (
'Quote' => 'Text',
'Company' => 'Varchar(255)',
'Name' => 'Varchar(255)'
);
function getCMSFields_forPopup() {
$fields = new FieldSet();
$fields->push( new TextField( 'Quote' ) );
$fields->push( new TextField( 'Company' ) );
$fields->push( new TextField( 'Name' ) );
return $fields;
}
static $has_one = array (
'HomePage' => 'HomePage'
);
}
Homepage.php
<?php
/**
* Defines the HomePage page type
*/
class HomePage extends Page {
static $db = array(
'H1Heading' => 'Text',
'BannerHeading' => 'Text',
'BannerTxt' => 'HTMLText'
);
static $has_one = array(
);
static $has_many = array (
'Quotes' => 'Quote'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldsToTab('Root.Content.Main', new TextField('H1Heading', 'H1 Heading'), 'Content');
$fields->addFieldsToTab('Root.Content.Main', new TextField('BannerHeading', 'Banner Heading'), 'Content');
$fields->addFieldsToTab('Root.Content.Main', new HtmlEditorField("BannerTxt","Banner Text"), 'Content');
$tablefield = new HasManyComplexTableField(
$this,
'Quotes',
'Quote',
array(
'Quote' => 'Quote','Company'=>'Company','Name' => 'Name'
),
'getCMSFields_forPopup'
);
$tablefield->setAddTitle( 'A Testimonial' );
$fields->addFieldToTab( 'Root.Content.Quotes', $tablefield );
return $fields;
}
}
class HomePage_Controller extends Page_Controller {
}
HomePage.ss Control Loop
<% if Quotes %>
<% control Quotes %>
<div class="testimonials">
<p><span class="quoteStart">“</span>$Quote<span class="quoteEnd">”</span></p>
<div class="quoteSource"><p>$Name<strong>$Company</strong></p></div>
</div>
<% end_control %>
<% else %>
No Quotes
<% end_if %>
I'm new to Silverstripe and think I have got everything correct. If anyone could let me know what I might have wrong, that would be great.
Thanks in advance
James