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

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

Open
SiM opened this issue Mar 4, 2021 · 3 comments

Comments

@SiM
Copy link

SiM commented Mar 4, 2021

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 )

@rogerhutchings
Copy link

I'm having the same issue, and it's also reported here: #51 (comment)

@butscharoni
Copy link

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.

@pierrepierrepierre
Copy link

pierrepierrepierre commented Nov 27, 2024

Hello all,
still running in this issue even after all updated, is that normal?
I'm running this locally :

  • SimpleSearch v2.3.0
  • Grav v1.7.48
  • Admin v1.10.48

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

Hi thanks for the tips @butscharoni it works to display the normal page.
But I don't see the results anymore...

I had to tweak some template files of my theme.
First, I did a copy of templates file simplesearch_results.html.twig, from user/plugin/simplesearch/ to my theme "partials" (templates/partials).
I later renamed it simplesearch_selfcontrolled.html.twig to avoid confusion.

Then, I removed the first line of the file :
{% extends 'partials/simplesearch_base.html.twig' %}
the results were not hidding the rest of the page anymore.

Finally, in the template of my page where I wanted the search bar, I just added this line :
{% include 'partials/simplesearch_selfcontrolled.html.twig' %}

And of course, in the frontmatter of the page, I manually specified the template and added the field required for simplesearch self-controlled page mode :

    process: false
    route: '@self'
    filters:
        -  '@self'
template: 'artworks'

I hope this is helping...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants