diff --git a/simplesearch.php b/simplesearch.php index 14294d6..6f062bd 100644 --- a/simplesearch.php +++ b/simplesearch.php @@ -96,7 +96,7 @@ public function onPagesInitialized() } // If a page exists merge the configs - if ($page) { + if (isset($page)) { $this->config->set('plugins.simplesearch', $this->mergeConfig($page)); } @@ -110,6 +110,12 @@ public function onPagesInitialized() return; } + // set the template is not set in the page header (the page header setting takes precedence over the plugin config setting) + if (!isset($page->header()->template)) { + $template_override = $this->config->get('plugins.simplesearch.template', 'simplesearch_results'); + $page->template($template_override); + } + // Explode query into multiple strings. Drop empty values $this->query = array_filter(array_filter(explode(',', $query), 'trim'), 'strlen'); @@ -225,15 +231,17 @@ public function onPagesInitialized() ); } - // if page doesn't have settings set, create a page - if (!isset($page->header()->simplesearch)) { + // Display simplesearch page if no page was found for the current route + $pages = $this->grav['pages']; + $page = $pages->dispatch($this->config->get('plugins.simplesearch.route', '/search'), true); + if (!isset($page)) { // create the search page $page = new Page; $page->init(new \SplFileInfo(__DIR__ . '/pages/simplesearch.md')); - // override the template is set in the config + // override the template is set in the plugin config (the plugin config setting takes precedence over the page header setting) $template_override = $this->config->get('plugins.simplesearch.template'); - if ($template_override) { + if (isset($template_override)) { $page->template($template_override); }