Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default vs. custom simplesearch.md #186

Merged
merged 1 commit into from
May 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions simplesearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand All @@ -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');

Expand Down Expand Up @@ -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);
}

Expand Down