Mark Handy
Mark Handy

Reputation: 1256

Kentico 9 search result transformation

We've noticed a bug when looking at French search results. in the CMS Desk, i've kept the Page Name in English for the French content. The issue is, these are showing on the French results page.

in the transformation, based off the default one, I present the clickable title like this:

<a href='<%# SearchResultUrl() %>' data-type="title" target="_blank" ><%#SearchHighlight(HTMLHelper.HTMLEncode(CMS.ExtendedControls.ControlsHelper.RemoveDynamicControls(DataHelper.GetNotEmpty(Eval("Title"), ""))), "<span class='highLight'>", "</span>")%></a>

Here's my thinking, if the Menu Caption is filled out, use that rather than title. How do i output DocumentMenuCaption without adjust the search fields on the menu page type?

I think my logic is, check if DocumentMenuCaption is emtpy, if it use, use Title.

Upvotes: 0

Views: 138

Answers (1)

probrandono
probrandono

Reputation: 528

You should be able to continue using GetNotEmpty and just pass in the DocumentMenuCaption first, something like this:

<%# GetNotEmpty(GetSearchValue("DocumentMenuCaption");Eval("Title")) %>

You may or may not need the "GetSearchValue" function, but that allows you to grab values from the object that may not be available in the default set of columns for the search results.

Alternatively, you should be able to use the IfEmpty() method:

<%# IfEmpty(GetSearchValue("DocumentMenuCaption"), Eval("Title"), GetSearchValue("DocumentMenuCaption")) %>

Both transformation methods taken from here (double check syntax on "GetNotEmpty" as there are different ways it's implemented: https://docs.kentico.com/k9/developing-websites/loading-and-displaying-data-on-websites/writing-transformations/reference-transformation-methods

You can read more about the search transformations here: https://docs.kentico.com/k9/configuring-kentico/setting-up-search-on-your-website/displaying-search-results-using-transformations

Upvotes: 2

Related Questions