public function getPage($path) { /** @var Pages $pages */ $pages = $this->grav['pages']; if ($path && $path[0] != '/') { $path = "/{$path}"; } $page = $path ? $pages->dispatch($path, true) : $pages->root(); if (!$page) { $slug = basename($path); if ($slug == '') { return null; } $ppath = str_replace('\\', '/', dirname($path)); // Find or create parent(s). $parent = $this->getPage($ppath != '/' ? $ppath : ''); // Create page. $page = new Page(); $page->parent($parent); $page->filePath($parent->path() . '/' . $slug . '/' . $page->name()); // Add routing information. $pages->addPage($page, $path); // Set if Modular $page->modularTwig($slug[0] == '_'); // Determine page type. if (isset($this->session->{$page->route()})) { // Found the type and header from the session. $data = $this->session->{$page->route()}; // Set the key header value $header = ['title' => $data['title']]; if (isset($data['visible'])) { if ($data['visible'] == '' || $data['visible']) { // if auto (ie '') $children = $page->parent()->children(); foreach ($children as $child) { if ($child->order()) { // set page order $page->order(1000); break; } } } if ($data['visible'] == 1 && !$page->order()) { $header['visible'] = $data['visible']; } } if ($data['name'] == 'modular') { $header['body_classes'] = 'modular'; } $name = $page->modular() ? str_replace('modular/', '', $data['name']) : $data['name']; $page->name($name . '.md'); // Fire new event to allow plugins to manipulate page frontmatter $this->grav->fireEvent('onAdminCreatePageFrontmatter', new Event(['header' => &$header])); $page->header($header); $page->frontmatter(Yaml::dump((array) $page->header(), 10, 2, false)); } else { // Find out the type by looking at the parent. $type = $parent->childType() ? $parent->childType() : $parent->blueprints()->get('child_type', 'default'); $page->name($type . CONTENT_EXT); $page->header(); } $page->modularTwig($slug[0] == '_'); } return $page; }