Hi,
I am trying to create some site wide content which will reside in the footer area of my site. I have created a DataExtension to extend siteconfig, which includes a DataObject as this is basically for sponsor images and you need to be able to add and remove as many as necessary.
From the backend I seem to have everything working, but don't seem to be able to access the data through the template, here is my code:
CustomSiteConfig.php
<?php
class CustomSiteConfig extends DataExtension {
private static $has_many = array(
'Sponsors' => 'Sponsor'
);
public function updateCMSFields(FieldList $fields) {
$config = GridFieldConfig_RelationEditor::create();
$config->getComponentByType('GridFieldDataColumns')->setDisplayFields(array(
'Link' => 'Link'
));
$sponsorfield = new GridField(
'Sponsors',
'Sponsor',
new DataList('Sponsor'),
$config
);
$fields->addFieldToTab('Root.Main', $sponsorfield);
}
}
?>
Sponsor.php
<?php
class Sponsor extends DataObject {
static $db = array (
'Link' => 'text',
);
static $has_one = array (
'SiteConfig' => 'SiteConfig',
'Image' => 'Image',
);
public function getCMSFields() {
$sizeMB = 2; // 2 MB
$size = $sizeMB * 1024 * 1024; // 2 MB in bytes
$uploadField = new UploadField('Image', 'Sponsor Image');
$uploadField->getValidator()->setAllowedMaxFileSize($size);
$fields = new FieldList(
new TextField('Link'),
$uploadField
);
return $fields;
}
}
?>
I have also updated the file in /framework/_config/config.yml to read:
SiteConfig:
extensions:
- CustomSiteConfig
In my template I am trying to access the data like this:
<% loop $SiteConfig.Sponsors %>
<p>$Link</p>
<% end_loop %>
Unfortunately this is not working for me, any ideas anyone?
Many Thanks