Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

Can't translate the page title of simplesearch plugin

Solved by pamtbaau View solution

Started by 01K 5 years ago · 3 replies · 474 views
5 years ago

Hi!
I'm using grav-plugin-simplesearch and can't figure out how to translate the page title in the head <title> section of the search results page.
Title is - Search Results
And I'm certain, that this is not:

YAML
  PLUGIN_SIMPLESEARCH:
    SEARCH_RESULTS:

variable

5 years ago

In languages.yaml the first few lines need to be something like:

YAML
en:
  PLUGIN_SIMPLESEARCH:
    SEARCH_PLACEHOLDER: 'Search …'
    SEARCH_RESULTS: 'Search Results Test'

That gives me the correct placeholder and the test heading indicated.

last edited 12/06/21 by Alan Coggins
5 years ago Solution

@01K,

Some background:
Plugin SimpleSearch does not manipulate the <title> element inside the <head> of the page. That's the territory of template base.html.twig from the current theme.

SimpleSearch displays the result of the search in a page pointed at by configuration setting route: /search which is set in config file simplesearch.yaml.

If page /user/pages/search does not exist, the plugin will use fall-back page /user/plugins/simplesearch/pages/simplesearch.md, which contains the hardcoded page title "Search Results" and a few other settings for the search results.

Solution:
So, if you create page /user/pages/search/default.md and add the following frontmatter from the fall-back page, you can set any title you like:

YAML
---
title: Your preferred title
order_by: date
order_dir: desc
template: simplesearch_results
---

If you have a multi-language site, you can add multiple pages, each with its own language extension and translated title and slug.

Of course, you can change setting route to any other route and create a page in a folder structure mimicking the route.

last edited 12/07/21 by pamtbaau
5 years ago

Thank you guys!
@zfiddler, pardon me, I've forgotten to display my all strings with correct translations. It was with language prefix:

YAML
lt:
  PLUGIN_SIMPLESEARCH:
    SEARCH_PLACEHOLDER: 'Ieškoti...'
    SEARCH_RESULTS: 'Paieškos rezultatai'

So, it wasn't working from the beginning...

I had to create a separate page, as @pamtbaau suggested

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 101 17 hours ago
General · by pamtbaau, 22 hours ago
1 68 22 hours ago
General · by Andy Miller, 1 day ago
0 53 1 day ago
General · by Marcel, 12 months ago
6 361 5 days ago
General · by Duc , 6 days ago
3 49 6 days ago