I’m not sure if this is the best way to handle this request, but I’d like to ask about considering this as an addition to the site_search liquid component. I had issues figuring out how to display search results on a client’s site and support offered me this information which I can’t find anywhere in the docs. Hope this helps. If I posted this incorrectly or in the wrong area, please correct me!
Thank you,
- Ryan
Search Results:
I asked support to help with getting search results to display on a search results page and this is how (tested and works!):
Add this code to the search results page:
{% component source: "Page", layout: "Site Search List", displayPagination: "true", emptyMessage: "No items found by keyword: <strong>{{request.request_url.params.SearchKeyword}}</strong>" , type: "site_search", limit:10, object:"collection" %}
<script>
$(document).ready(function()
{
initSearchKeyword();
});
/***************Search*******************/
function initSearchKeyword() {
var params = window
.location
.search
.replace('?', '')
.split('&')
.reduce(
function (p, e) {
var a = e.split('=');
p[decodeURIComponent(a[0])] = decodeURIComponent(a[1]);
return p;
},
{}
);
var string = params['searchkeyword'];
var highlightWord = function(text){
var searchHtmlCollection = document.getElementsByClassName('searchElem');
var arr = searchHtmlCollection.length;
for (i = 0; i < arr; i++) {
var html = searchHtmlCollection[i].innerHTML;
var word = "( " + text + " )";
var match = new RegExp(word, "gi");
html = html.replace(match, "<span style='font-weight: bold;'>$1</span>");
searchHtmlCollection[i].innerHTML = html;
}
};
highlightWord(string);
}
/***************End Search*******************/
</script>
Create a new Page Layout (https://prnt.sc/ov80pl) called Site Search List (or call it whatever you want, just be sure the name of the new Layout matches the layout identified in the liquid tag). And then once you have the layout created (https://prnt.sc/ov80tl), code/style the list layout however you like.