Skip to content

Instantly share code, notes, and snippets.

@pigeonflight
Last active July 27, 2017 20:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pigeonflight/4158a8c1571ccfd01766ed6c3665a56d to your computer and use it in GitHub Desktop.
Save pigeonflight/4158a8c1571ccfd01766ed6c3665a56d to your computer and use it in GitHub Desktop.
Use patternslib inject and auto-submit to quickly build a standalone search form in Plone

Setup

  • This requires Plone 5.1 with plone.patternslib and rapido.plone installed

The files should be located in your theme under the rapido folder of your theme. The tree might look like this:

rapido
    views
        blocks
            searchdemo.pt
            searchdemo.yaml

To see the demo visit {yourplonesite}/@@searchdemo

Extending

To extend the custom form take a look at queries generated by Plone's default search. Visit {yourplonesite}/@@search

Here's a typical query filtered to only return news item:

search?    sort_on=&sort_order=&SearchableText=bookings&advanced_search=False&portal_type%3Alist=News+Item&created.query%3Arecord%3Alist%3Adate=1970-01-02&created.range%3Arecord=min

The important part is &portal_type%3Alist=News+Item. Using this knowledge we could create a custom form that only returns News items by adding a hidden input field in searchdemo.pt`:

<input type="hidden" name="portal_type:list" value="News Item" />
<form action="@@search#search-results-wrapper" data-pat-inject="target: #search-results" class="pat-inject pat-autosubmit">
<input type="text" name="SearchableText" />
</form>
<div id="search-results">
hello
</div>
view:
id: searchdemo
with_theme: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment