I would like too modify the search results displayed within my transformation so that they have a different icon based on there URL or NodeAliasPath. I have the same page type appear in mtuliple part sof the site so I would like to display as
Search results 1st page is in /home/content/dog/disease 2nd page is in /home/content/cat/disease Both pages would use the same page type and template
In the search results I would like to say if the page is in the /dog/ path then display icon A, if in path /cat/ then display icon B and if in neither display icon Z
Any help appreciated as still getting to terms with searches and the relevant results.
Well, this is actually a good example for custom transformation method. You can implement one and as its parameter you send the NodeAliasPath of currently listed item. In the code you simply check what section it is and return the icon you need:
https://docs.kentico.com/display/K9/Adding+custom+methods+to+transformations
Hi Alan,
Also, you can write conditional expression in the transformation:
<%# Eval("NodeAliasPath").ToString().StartsWith("/home/content/dog", StringComparison.CurrentCultureIgnoreCase) ? "dog.jpg" : "cat.jpg" %>
I will investigate the custom methods (this normally proves harder as my Visual Basic skills are minimal still). I have tried the conditional expression in the transformation and it gives an error of [CMSAbstractTransformation.DataBind]: Object reference not set to an instance of an object.
[CMSAbstractTransformation.DataBind]: Object reference not set to an instance of an object.
It's weird, looks like Eval method returns null. Could you check that you select NodeAliasPath column in your datasource? Or you can add only <%# Eval("NodeAliasPath") %> to check what this method returns.
<%# Eval("NodeAliasPath") %>
Hi Anton, I have cleared out the entire transformation and used just the line as suggested and it displays no text at all in the results but shows there are 145 pages worth of results. I then changed the transformation to <%# SearchResultUrl() %><%# Eval("NodeAliasPath") %> and it the does show a list of results URLs as I would expect, /clinical-reference/canis/illustration/parsons-jack-russell-terrier /clinical-reference/canis/illustration/american-staffordshire-terrier Should that mean that rather usinhg the NodeAliasPAth I should be able to use your original code with SearchResultsURL instead?
<%# SearchResultUrl() %><%# Eval("NodeAliasPath") %>
/clinical-reference/canis/illustration/parsons-jack-russell-terrier /clinical-reference/canis/illustration/american-staffordshire-terrier
Please, sign in to be able to submit a new answer.