Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba

DOM control loop template in siteconfig

Go to End

5 Posts   2519 Views


Community Member, 25 Posts

29 April 2012 at 12:42am

I am Swf banner, that randomly rotates for each page.

I have made a Dataobject, with file upload and alternate text/images fine in CMS.

But When trying to loop thru in templates i get no data even tho i see several items in the DOM inside siteconfig.


Community Member, 25 Posts

29 April 2012 at 12:46am

Here's my Dataobject code(SwfBannerResource.php)


class SwfBannerAdResource extends DataObject
static $db = array (
'AdName' => 'Text',
'Link' => 'Text'


static $has_one = array (
'Attachment' => 'Image', //Needs to be an image
'Swf' => 'File',

'SiteConfig' => 'SiteConfig'


public function getCMSFields_forPopup()
return new FieldSet(
new TextField('AdName'),
new TextField('Link'),
//new FileIFrameField('Attachment'),
new FileAttachmentField('Attachment', 'Static jpeg 1017px by 112px'),
new FileAttachmentField('Swf', 'Swf 1017px by 112px')


Here's my Site config (part of it)

public function updateCMSFields(FieldSet &$fields) {

$manager = new DataObjectManager(
'AdName' => 'AdName',
'Link' => 'Link',
'Attachment.Name' => 'Attachment',
'Swf.Name' => 'Swf',

$manager->setUploadFolder("PublicationPage-" . $this->ID);
$manager->setAllowedFileTypes(array ('pdf','doc'));

$fields->addFieldToTab("Root.SwfBanner", $manager);

And here's my template:

<% control SiteConfig %>

<% control SwfBanners %>
<div id="FlashContainer">
<a href="$Link">
<script type="text/javascript">
/* <![CDATA[ */
"1017", "112",
/* ]]> */
<% end_control %>
<% end_control %>

I haven't got randomizing yet, I'm just trying to loop thru all the SwfBanner data object and get them to display.

But only "/assets/" is output by the template even tho in the CMS i can see the files, urls, etc.

Any Ideas?

Thanks in advance


Community Member, 8 Posts

22 May 2012 at 1:44am

Edited: 22/05/2012 2:21am

I am having the same sort of problem....
Is there anybody who could help us with that?

I can access any field I create in any tab of the SiteConfig. however when I try to run a control loop to a

// Relation into SiteConfig extension


// Relation into DataObject extension (Car)


The following loop
// .ss File

<% SiteConfig %>
   <% Cars %>
   <% end_control %>
<% end_control %>

does not return any element from the list that I can manage using DataObjectManager(this works very smooth), which seats on a new Tab created in the SiteConfig.
It is like Cars does not exist.

Thanks in advance....

PS: This Forum has been clarified lot of my doubts!!! (But I still have a lot to go....)

Cheers to you all..


Community Member, 8 Posts

22 May 2012 at 2:18am

I tried to create the following function at Page_Controller class

function CarList() {
         return DataObject::get('Car');

then created a control loop to CarList in my template.
no success....


Community Member, 8 Posts

22 May 2012 at 2:36am

Edited: 22/05/2012 2:37am


Instead of creating the function inside the Page_Controller, I inserted this function inside the Decorator class that extends the Page_Controller.


   class CarGalleryDecorator_Config extends DataObjectDecorator {
      ..... // Here I define the relations and create a new tab that holds the DOM

   class CarGalleryDecorator_Controller extends Extension {

      function SidebarLinkList() {
         return DataObject::get('SidebarLink');

and in mysite/_config.php

Object::add_extension('Page_Controller', 'CarGalleryDecorator_Controller');
DataObject::add_extension('SiteConfig', 'CarGalleryDecorator_Config');

For some reason I would think that what was done in the previous post would work the same way as this one.
But not....

By the way, happier now that it works!!!!