/** * Returns all children for this page * * @return Children */ public function children() { if (isset($this->cache['children'])) { return $this->cache['children']; } $this->cache['children'] = new Children($this); $inventory = $this->inventory(); // with page models if (!empty(static::$models)) { foreach ($inventory['children'] as $dirname) { $child = new Page($this, $dirname); // let's create a model if one is defined if (isset(static::$models[$child->intendedTemplate()])) { $model = static::$models[$child->intendedTemplate()]; $child = new $model($this, $dirname); } $this->cache['children']->data[$child->id()] = $child; } // without page models } else { foreach ($inventory['children'] as $dirname) { $child = new Page($this, $dirname); $this->cache['children']->data[$child->id()] = $child; } } return $this->cache['children']; }