Customized search results
I have a page with a list of questions and answers in an expandable list.
Also on this page I have a search box, when I search the list I get the results with links to separate pages. I want to display the result in a expandable list with only the title of the list item showing.
I've made a new template for the search result and tried to copy over some code from the template for the expandable list but it only shows the title with nothing happening when you click it.
Anyone have any suggestions?
Best regards
The template:
<%@ Control Language="C#" %>
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI" TagPrefix="sitefinity" %>
<%@ Register Assembly="Telerik.Sitefinity.Search.Impl" Namespace="Telerik.Sitefinity.Services.Search.Web.UI.Public" TagPrefix="sfSearch" %>
<
sfSearch:SearchBox
ID
=
"topSearchBox"
runat
=
"server"
/>
<
sitefinity:SitefinityLabel
id
=
"resultsStats"
runat
=
"server"
WrapperTagName
=
"p"
CssClass
=
"sfsearchResultStatistics"
Text="<%$Resources:SearchResources, SearchResultsStatusMessage %>" />
<
asp:Repeater
ID
=
"resultsList"
runat
=
"server"
>
<
HeaderTemplate
>
<
dl
class
=
"sfsearchResultsWrp sfsearchReultTitleSnippetUrl"
>
</
HeaderTemplate
>
<
ItemTemplate
>
<
h2
class
=
"sflistTitle"
>
<
asp:Literal
runat
=
"server"
Text='<%# Eval("Title") %>' />
</
h2
>
<
telerik:RadListView
ID
=
"listItemsControl"
runat
=
"server"
ItemPlaceholderID
=
"ItemsContainer"
EnableEmbeddedSkins
=
"false"
EnableEmbeddedBaseStylesheet
=
"false"
>
<
LayoutTemplate
>
<
ul
class
=
"sflistList"
>
<
asp:PlaceHolder
ID
=
"ItemsContainer"
runat
=
"server"
/>
</
ul
>
</
LayoutTemplate
>
<
ItemTemplate
>
<
li
class
=
"sflistListItem"
>
<
h3
class
=
"sflistItemTitle"
>
<
asp:LinkButton
runat
=
"server"
ID
=
"listItemToggleLnk"
class
=
"sflistItemToggleLnk"
Text='<%# Eval("Title") %>' OnClientClick="return false;" />
</
h3
>
<
div
runat
=
"server"
ID
=
"listItemContent"
class
=
"sflistItemContent"
style
=
"display: none;"
>
<
asp:Literal
runat
=
"server"
Text='<%# Eval("Content") %>' />
</
div
>
</
li
>
</
ItemTemplate
>
</
telerik:RadListView
>
</
ItemTemplate
>
<
FooterTemplate
>
</
dl
>
</
FooterTemplate
>
</
asp:Repeater
>
<
sitefinity:Pager
ID
=
"pager"
runat
=
"server"
/>
<
sfSearch:SearchBox
ID
=
"bottomSearchBox"
runat
=
"server"
/>
Anyone have any suggestions?
Since the answers are all rather short I was thinking of showing the content in full always. I will try that now but I rather prefer the expandable list if possible.
Hello Andreas,
You can try the following approach, changing the search results template, for example like:
<%@ Control Language="C#" %>
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI" TagPrefix="sitefinity" %>
<%@ Register Assembly="Telerik.Sitefinity.Search.Impl" Namespace="Telerik.Sitefinity.Services.Search.Web.UI.Public" TagPrefix="sfSearch" %>
<
sfSearch:SearchBox
ID
=
"topSearchBox"
runat
=
"server"
/>
<
sitefinity:SitefinityLabel
id
=
"resultsStats"
runat
=
"server"
WrapperTagName
=
"p"
CssClass
=
"sfsearchResultStatistics"
Text="<%$Resources:SearchResources, SearchResultsStatusMessage %>" />
<
asp:Repeater
ID
=
"resultsList"
runat
=
"server"
>
<
HeaderTemplate
>
<
dl
class
=
"sfsearchResultsWrp sfsearchReultTitleSnippetUrl"
>
</
HeaderTemplate
>
<
ItemTemplate
>
<
li
class
=
"sflistListItem sflistitem"
data-sf-provider
=
'Default'
data-sf-id='<%# Eval("Id")%>' data-sf-type="Telerik.Sitefinity.Lists.Model.ListItem">
<
h3
class
=
"sflistItemTitle sftitle"
>
<
asp:LinkButton
runat
=
"server"
ID
=
"listItemToggleLnk"
class
=
"sflistItemToggleLnk"
Text='<%# Eval("Title") %>' OnClientClick="return false;" data-sf-field="Title" data-sf-ftype="ShortText"/>
</
h3
>
<
div
runat
=
"server"
ID
=
"listItemContent"
class
=
"sflistItemContent sfcontent"
style
=
"display: none;"
data-sf-field
=
"Content"
data-sf-ftype
=
"LongText"
>
<
asp:Literal
runat
=
"server"
Text='<%# Eval("Content") %>' />
</
div
>
</
li
>
</
ItemTemplate
>
<
FooterTemplate
>
</
dl
>
</
FooterTemplate
>
</
asp:Repeater
>
<
sitefinity:Pager
ID
=
"pager"
runat
=
"server"
/>
<
sfSearch:SearchBox
ID
=
"bottomSearchBox"
runat
=
"server"
/>
<
script
language
=
"javascript"
type
=
"text/javascript"
>
$(".sflistItemTitle.sftitle").click(function()
$(this).next().toggle("slow", function()
// ...
);
);
</
script
>
Awesome. It works as expected. Thanks.
Another problem appeared though. I have a CustomSearchResult set in the ViewMap which is used everywhere but I want the regular search results on the site to have a different template.
I have tried deleting the viewmap setting and created 2 templates within the search result (see screenshot). But when I do the standard sitefinity search result design is used (not the one i used In the ViewMap)
Is their something I need to set in the advanced tab?
Hi Andreas,
Generally speaking, when you have ViewMaped template it will be used wherever the type is called. Once you delete the ViewMap you need to restart the application in order to stop using that template.
Regarding the search results - the template selected in the search results widget dropped on a page will be used. In case you need different templates for Lists search and other search, you need to have different pages where the Search box is pointing to (where the respective Search results widget is placed).
For example: Standard search box points to "Search results" page but Lists search box points to "List Search results" page, where the respective template is selected (as per your screenshot).
Regards,
Svetoslav Manchev
Telerik
Thanks for the reply but I think you misunderstood.
The search result on the List where I have the expandable template selected shows the standard/default searchresult template, Not my old custom template.
Is this a behavior for it when the template you have selected does not work?
Best regards
This is very weird.
On my standard site search my custom search template worked (the text is in swedish)
Just to test, I changed to the expandable template. Then the results shows up in the default layout (english)
I change back to the regular custom template again, but the results stays in default layout....
what :S
Hi Andreas,
Changing between the templates in the search results widget seems works fine.
Can you please provide a video demonstration of the steps performed? Alternatively, in order to inspect your project more detailed you can open a support ticket. Once you have the solution you can share it with the community.
Regards,
Svetoslav Manchev
Telerik
Created new page and added the search controls.
Chose the titlesonly -> Shows only titles
Chose the standard -> Shows standard
Chose the titlesonly -> Shows only titles (so changing seems to work)
Chose the expandable (with your supplied code)-> Shows standard
Chose the titlesonly -> Still shows standard
Do I have to do something more with the created templates? (I created them from the select template window)
Anyone?
Hello Andreas,
Thank you for the detailed description and the video demonstration.
I have tested the same scenario and it works fine, and the templates are changing. I can recommend you to open a support ticket in order to inspect your project more detailed.
You can look for any errors when using your template (~/App_Data/Sitefinity/Log). Remove the files there in advance, reproduce the issue and check for any files generated. You can check also for any browser errors.
Regards,
Svetoslav Manchev
Telerik
I have just run into a similar issue when changing the search results template as well. Using Sitefinity Version 10.1. In Design and Preview Mode the Search Results show that they are using my new template. The preview mode even shows the search results correctly using the new template when you append the search string (Example: localhost:10165/.../Preview However when i go to the live page it reverts back to the default template. Andreas, what was your resolution. I have already delete the page and recreated etc.