Gravatar for

Question by DEEPTHI KATTA, Oct 19, 2016 5:02 PM

Image Carousel on Search Result Item

Hi There,

One of our design requirements is to have multiple images that are related to search result item within sitecore. It is actually a Image Tree list, where they can choose multiple images that they would like to add on each appropriate sitecore item.

I see this link on Coveo documentation, but, it basically talks about simple Image field and not treelist field. Thoughts if we can do this?

1 Reply
Gravatar for

Answer by ssartell, Oct 19, 2016 5:25 PM

One trick I've used on previous sites is to create a computed index field in Sitecore that returns serialized JSON (via Json.NET) that you can then JSON.parse() on the client side. This allows you to pull any sort of data structure out of Coveo along with your results. Each result could have a field that contains an array of slide objects that have the image url, caption, etc. Converting that data into markup is then just a matter of standard underscore templating and using whatever js carousel you want. Does that make sense?

Gravatar for

Comment by DEEPTHI KATTA, Oct 19, 2016 8:19 PM

I think I understand, so, we need to add a computed index field (pure sitecore one) on tree list field that would actually have selected image fields(bunch of them) Then manipulate that field from client side - so, can this field be accessible on Coveo side using typical Model.ToCoveoFieldName(Sitecore computed index name)? Since I am fairly new to computed indexes, could you point me to some references that I can read up on that would help me crack this.

Gravatar for

Comment by ssartell, Oct 19, 2016 8:29 PM

Computed index fields aren't specific to one field or another. It creates an entirely new field based on the item which means you could pull data from multiple fields or even pull in related items to construct whatever value you want. In this case, you're spitting out a string of json of an array with your images and other data.

As for accessing the data, you would use Model.ToCoveoFieldName as you mentioned. Keep in mind that Underscore templates are pretty much JavaScript so you have access to JSON.parse and anything else in js.

Ask a question