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.

All other Modules /

Discuss all other Modules here.

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

access SiteConfig fields from subsites in a template


Go to End


2 Posts   1082 Views

Avatar
VanceK

Community Member, 18 Posts

9 December 2013 at 4:19pm

Hi, I'm using SS 3.1.2 and the Subsites module. I've extended SiteConfig to add several database fields so that each subsite can enter its own data (Contact info, address, Google map coords, etc.). From the main site I would like to be able to retrieve the subsite data from SiteConfig to list in a template, but so far I am unable to do this. Can anyone offer any help or direction?

Thanks in advance!

Avatar
VanceK

Community Member, 18 Posts

10 December 2013 at 1:34am

This works. Putting this in my controller and looping on $Subsites in the template:

public function getSubsites() {
$db = new SQLQuery();
$db->setFrom('SiteConfig');
$db->setWhere('SubsiteID > 0');
$records = $db->execute();
$items = array();
foreach($records as $record){
$items [] = new $record['ClassName']($record);
}
$sites = new ArrayList();
$sites ->merge($items);
return $sites;
}