grav-plugin-simplesearch icon indicating copy to clipboard operation
grav-plugin-simplesearch copied to clipboard

Self-Controlled Page configuration doesn’t work: it always display results even before launching a search

Open SiM opened this issue 4 years ago • 3 comments

Hi,

I have a simple blog page, where I have added a simplesearch header as described on the doc:

title: Blog
content:
  items: '@self.children'
  limit: 5
  order:
    by: date
    dir: desc
  pagination: true
  url_taxonomy_filters: true
simplesearch:
  process: true
  route: '@self'
  filters:
    - '@self'
  filter_combinator: and

And now when I go on the blog page, I no longer have the list of my articles but the display of the results (which is empty because I did not launch a search). I see in the debug bar that simpleearch_result is called: info Routed to page /blog (type: simpleearch_results). If I understand what is written in the doc, it is the blog template that should be called instead, even if a search is launched from this page (and in this case the collection is replaced by the search results).

I’m using Grav v.1.7.7 and SimpleSearch v2.2.1 (with default settings) Reproduced with grav skeleton onepage site

(problem reproduced at least by another person, see the forum thread here: https://discourse.getgrav.org/t/simplesearch-self-controlled-page-configuration-doesnt-work-it-always-display-results-even-before-launching-a-search/16408 )

SiM avatar Mar 04 '21 20:03 SiM

I'm having the same issue, and it's also reported here: https://github.com/getgrav/grav-plugin-simplesearch/issues/51#issuecomment-930031128

rogerhutchings avatar Oct 16 '21 10:10 rogerhutchings

I just ran into the same issue. This used to work in older versions of the plugin but does not now. In the past, when a template was set in the plugins settings, this would override the page template. At the moment, this works as follows:

    if (!isset($page->header()->template)) {
        $template_override = $this->config->get('plugins.simplesearch.template', 'simplesearch_results');
        $page->template($template_override);
    }

So it will override the template whenever there is none set in the page header. Now I don't know enough about grav to be sure if this is a mistake in the plugin because the template can be set by the file name and would thus never be in the header or if the page->header() function has changed and used to report template as a header when only set via the file name.

Regardless, this seems to be a bug.

A quick fix for anyone who needs this functionality is manually setting the template in the page header.

butscharoni avatar Apr 07 '22 14:04 butscharoni