8

I am using the following code in a custom display template for my search results to show the correct content type of an item:

_#=ctx.CurrentItem.ContentType=#_

The good part is that it returns the correct content type (e.g. Sales docs), but it returns also the MIME type: application/word. How to only show the content type text without the MIME type?

2

I fixed this with the following (dirty) JavaScript code:

        var CT_s1 = ctx.CurrentItem.ContentType;
        var CT_s2 = CT_s1.replace(/\s/g, '_');  
        var CT_s3 = CT_s2.lastIndexOf('__');
        var CT_s4 = CT_s2.substring(CT_s3 +1);
        var CT_label = CT_s4.replace(/_/g, ' ');

And in the item display template:

<span>_#=CT_label=#_</span>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.