Jump to:

10990 Posts in 2727 Topics by 1818 members

All other Modules

SilverStripe Forums » All other Modules » access SiteConfig fields from subsites in a template

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 173 Views
  • VanceK
    Avatar
    Community Member
    17 Posts

    access SiteConfig fields from subsites in a template Link to this post

    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!

  • VanceK
    Avatar
    Community Member
    17 Posts

    Re: access SiteConfig fields from subsites in a template Link to this post

    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;
       }

    173 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.