Custom Modules Search

Hello,

I have two questions related to the custom modules search form.

  1. I set up a search form that works fine. When I do a search the results are displayed correctly. The problem is that when I access the page (before permform the search) all the items are displayed while I would like that the results will be diplayed only when the search is done.

This is my search results component:

{% component source: “Custom Modules Name”, layout: “List”, sortBy: “name”, sortOrder: “ASC”, limit: “20”, displayPagination: “true”, object: “item”, isSearchResult: “true”, type: “module” %}

  1. The same search module is also displayed in a pop-up level and in a sidebar and I need to show the search results in a different page.
    I don’t understand how to set the display of results on a specific page. Is it possible to set in the form action as in BC? Can I define via JS the page result?

Thanks a lot!

Hi @Rebecca, welcome to the forum!

Yes to both your questions :slight_smile:

Below is some sample code that does both, redirect your search form (via the addition of an action attribute), and displays the search component only when the search parameter is present in the URL:

<form action="/search-results-page"> <!-- this action attribute does the redirect -->
	<input type="hidden" name="prop_ModuleId" value="1999" >
	<label>Keywords</label>
	<input type="text" name="prop_KeyWords" maxlength="255" value="{{request.request_url.params.prop_KeyWords}}" >
	<input type="submit" value="Search" >
</form>

{% if request.request_url.params.prop_ModuleId %} <!-- this Liquid condition checks for the search param in the URL -->
{% component source: "Your Module", layout: "List", isSearchResult: "true", type: "module" %}
{% endif %}

Hi @Adam.Wilson, thanks a lot for your help!

Hi,

Could anyone know why search result is giving incorrect result?
The link is

https://stpauls.trialsite.co/resources/sermons-by-kenn

Try searching for hope and you will notice first result doesn’t have a word hope in the title.

Thanks!

Hi @Yunnek
Doesn’t look like any search term/keyword is working and all items are being returned with any search.
Double-check the module ID used in the search form is the correct ID of the Custom Module.
Also, try re-indexing the site.

If ID is correct and reindex doesn’t help, can you post the code you have on the search page.

Hi Adam,

Thank you for replying quickly.

I tried clicking the button on top of the admin page called “Rebuild index” and it still doesn’t show correct search result.

The ID is correct. Value 2500.
Here is the code.

<form class="search-form">
    <input type="hidden" name="prop_ModuleId" value="2500" >
    <label>Keywords</label>
    <input type="text" name="prop_KeyWords" maxlength="255" value="{{request.request_url.params.prop_KeyWords}}" >
</form>

{% if request.request_url.params.prop_ModuleId %}
   {% component type: "module", source: "sermon downloads", layout: "_Layouts_custom_audio-list_tpl", displayPagination: "false" %}
{% endif %}

I see the issue. Your component tag doesn’t have the isSearchResult parameter included.
See the docs here for the parameters and options:
https://docs.treepl.co/component-types/module-custom-modules

But basically it should be something like this:

{% component type: "module", source: "sermon downloads", layout: "_Layouts_custom_audio-list_tpl", displayPagination: "false", isSearchResult: "true" %}

Wow!! Thank you so much Adam. It is now working prefectly.

1 Like