Clarify search form example
Addresses #6, which highlights some confusion about the example search form. This updates it to use the `link` filter used in Pico templates to render URLs appropriate for the value of the `rewrite_url` config variable.
This commit is contained in:
10
README.md
10
README.md
@@ -61,11 +61,11 @@ in a sub-folder) and see the search results for "foobar" listed.
|
|||||||
|
|
||||||
## The search form
|
## The search form
|
||||||
|
|
||||||
How to design your search form is up to you, but here's a very rudimentary example which you can put either in a
|
How to design your search form is up to you, but here's a very rudimentary example which you can put in a
|
||||||
template file or on a specific page.
|
template file:
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<form id="search_form" action="/search">
|
<form id="search_form" action="{{ "search"|link }}">
|
||||||
<label for="search_input">Search the site:</label>
|
<label for="search_input">Search the site:</label>
|
||||||
<input type="search" id="search_input" name="q" />
|
<input type="search" id="search_input" name="q" />
|
||||||
<input type="submit" value="Search" />
|
<input type="submit" value="Search" />
|
||||||
@@ -74,12 +74,14 @@ template file or on a specific page.
|
|||||||
// Intercept form submit and go to the search results page directly, avoiding a redirect
|
// Intercept form submit and go to the search results page directly, avoiding a redirect
|
||||||
document.getElementById('search_form').addEventListener('submit', function (e) {
|
document.getElementById('search_form').addEventListener('submit', function (e) {
|
||||||
var search_terms = document.getElementById('search_input').value;
|
var search_terms = document.getElementById('search_input').value;
|
||||||
location.href = '/search/' + encodeURIComponent(search_terms);
|
location.href = '{{ "search"|link }}/' + encodeURIComponent(search_terms);
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If you want to put it in a content file, you'll have to adjust the template variables accordingly, ie. instead of `{{ "search"|link }}` you'd use something like `%base_url%?search`.
|
||||||
|
|
||||||
## Configuration options
|
## Configuration options
|
||||||
|
|
||||||
You can exclude certain pages from being included in the search results by using the configuration option `search_excludes`.
|
You can exclude certain pages from being included in the search results by using the configuration option `search_excludes`.
|
||||||
|
|||||||
Reference in New Issue
Block a user