Gravatar for arulselvan.arivazhagan@cfainstitute.org

Question by Arulselvan, Jan 3, 2018 10:21 PM

Index field with html tags?

I just want to index data like "America\n\brAustralia\n\br".

I have created custom field and return the above data to the coveo cloud. But i couldnt see the data with "\n\br"

Is there any way to index it??

Thanks in advance.

2 Replies
Gravatar for arulselvan.arivazhagan@cfainstitute.org

Answer by Arulselvan, Jan 10, 2018 4:05 PM

Simon,

Thanks for your help. Appreciated.

i found the solution for that, i used "unescapte" method from underscore.js

<div> {{= unescape(raw.@(Model.ToCoveoFieldName("degreeandprogram", false)))}}</div>

Gravatar for slangevin@coveo.com

Comment by Simon, Jan 10, 2018 6:54 PM

Ok good find. Still I would say for this type of list using a multi-value field would be a better approach. Still thanks for looking at it, it will help others.

Gravatar for slangevin@coveo.com

Answer by Simon, Jan 5, 2018 3:47 PM

It should pretty much do it out of the box.

In my case I am using Coveo for Sitecore and in Sitecore I have a rich text field called abstract.

You can see in the screenshot bellow that the field was indexed with the html p tags.

Is that what you are looking for?

Gravatar for arulselvan.arivazhagan@cfainstitute.org

Comment by Arulselvan, Jan 5, 2018 4:16 PM

Yes exactly. Like "abstract" in ur screenshot, i have computed field "Article". i just wanted to save data with tags like "\p" in order to render the fields with style in the UI. Below code im using to return value.

        ID indexableItemID = new ID(p_Indexable.Id.ToString());
                Item currentItem = Context.ContentDatabase.GetItem(indexableItemID);
                if (currentItem != null)
                {
                    if (!string.IsNullOrWhiteSpace(computedTemplatesGuid))
                    {
                        //Flag to validate IsItemDerivedFromBaseTemplate 
                        ID templateID = new ID(computedTemplatesGuid);
                        var isItemDerivedFromBaseTemplate = ItemExtensions.IsItemDerivedFromBaseTemplate(currentItem, templateID);
                        if (isItemDerivedFromBaseTemplate)
                        {
                            return currentItem.Fields[computedItem].Value;
                        }
                    }
                }
<br>
Gravatar for arulselvan.arivazhagan@cfainstitute.org

Comment by Arulselvan, Jan 5, 2018 8:40 PM

I tried by adding return type as "string". Still i couldnt see the tags in the coveo cloud.

Gravatar for arulselvan.arivazhagan@cfainstitute.org

Comment by Arulselvan, Jan 8, 2018 7:36 PM

I achieved by replacing "\n" with "\\n".

Now i count see the indexd value with html tag.

But when i render in the UI, the style is not getting applied.

Below code,

<span class="CoveoFieldValue" data-field='@(Model.ToCoveoFieldName("degree"))'></span>

UI:

Is there any way to render with applied html styles?

thanks in advance.

Gravatar for arulselvan.arivazhagan@cfainstitute.org

Comment by Arulselvan, Jan 10, 2018 1:38 AM

I tried as you suggested,

<div> {{-raw.@(Model.ToCoveoFieldName("degreeandprogram", false))}}</div>

Still it is not applying.

Am i missing anything here?

Gravatar for arulselvan.arivazhagan@cfainstitute.org

Comment by Arulselvan, Jan 10, 2018 4:05 PM

Simon,

Thanks for your help. Appreciated.

i found the solution for that, i used "unescapte" method from underscore.js

<div> {{= unescape(raw.@(Model.ToCoveoFieldName("degreeandprogram", false)))}}</div>

Ask a question