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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

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

siteconfig dom logos


Go to End


3 Posts   1045 Views

Avatar
Guy Van Bael

Community Member, 61 Posts

20 April 2012 at 3:11am

Edited: 20/04/2012 3:12am

Hi,

I'm trying to add dom to siteconfig (ss2.4.7) that holds logo's which have to be visible on every page. All goes well.
I created logo.php, CustomSiteConfig.php and so i can add logo's and their description to the siteconfig. To test, i added 2 of them.

The problem starts when i want to display the logo's in the template
in the include file is

<div id="logos">
		<% control SiteConfig.Logos %>
					<p>$SiteConfig.description</p>
		<% end_control %>
	</div> 

When i display the page in the browser, i can see in the pagesource that i finds 2 records (2 times p tag). However. It doesn't display the description from the database. Tried to display the logo itself (which is the final goal) using $SiteConfig.LogoImage and $SiteConfig.LogoImage.URL, but no luck.

solution anyone?

This is the code for CustomSiteConfig.php

<?php
 
class CustomSiteConfig extends DataObjectDecorator {
 
function extraStatics() {
return array(
'db' => array(
                'Headertext' => 'HTMLText'
            ),
'has_many' => array(
'Logos' => 'Logo'
)
);
}
public function updateCMSFields(FieldSet &$fields) {
 
$manager = new SiteConfig_DataObjectManager(
$this->owner,
'Logos',
'Logo',
array('LogoImage' => 'logo',
 'description' => 'Omschrijving'
),
'getCMSFields_forPopup'         
);   
$manager->setParentClass("SiteConfig"); 
$manager->setSourceID($this->owner->ID);
$fields->addFieldToTab("Root.logos", $manager);
 
}
}
class SiteConfig_DataObjectManager extends DataObjectManager {
function setSourceID($val) {
if (is_numeric($val)) {
$this->sourceID = $val;
}
}
function sourceID() {
if (isset($this->sourceID) && $this->sourceID !== null && is_numeric($this->sourceID)) {
return $this->sourceID;
}
return parent::sourceID();
}
}

this is Logo.php

<?php

class Logo extends DataObject 
{ 
static $db = array ( 
'description' => 'Text'
); 
    
    
    
static $has_one = array ( 
   'SiteConfig' => 'SiteConfig', 
   'LogoImage' => 'Image' 
); 
    
public function getCMSFields_forPopup() 
   { 
        return new FieldSet(
            new TextField('description'),
            new FileIFrameField('LogoImage')
      ); 
   } 
}

?>

Avatar
Guy Van Bael

Community Member, 61 Posts

20 April 2012 at 9:27pm

Found the solution: Seems like you have to leave out the Siteconfigbit when adressing dom-fields related to the siteconfig

this is the new code for the templateinclude


<div id="logos">
		<% control Siteconfig.Logos %>
					<p>$LogoImage</p>
		<% end_control %>
	</div>

Avatar
martimiz

Forum Moderator, 1391 Posts

22 April 2012 at 7:48am

You are right - but this is normal SilverStripe behaviour, so it's not a 'DOM' thing :-) A control structure always iterates a set of DataObjects and within that structure the scope is that of the DataObject.

In this case <% control SiteConfig.Logos %> loops all Logo objects in Logos, so within the control it's enough to just address its properties