0

I have the following script that replaces the field value with an image. Works great, but I would like the field value and the image to be displayed. I have tried using img + field.value to no avail. How do I get both?

(function () {

    var statusFieldCtx = {};
    statusFieldCtx.Templates = {};
    statusFieldCtx.Templates.Fields = {
        "ProspectRate": {
            "View": StatusFieldViewTemplate
        }
    };

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(statusFieldCtx);
})();

function StatusFieldViewTemplate(ctx) {



    if (ctx.CurrentItem.ProspectRate <=25)
    {
        return "<img src='https://mysite.sharepoint.com/SiteAssets/Pick_Red-01.png'>";
}}
0

As per your previous post, you are able to set image. Now instead of using tag use div tag and set image as a background of the div and div will have content as the field value.

Try something like this

    (function () {

    var statusFieldCtx = {};
    statusFieldCtx.Templates = {};
    statusFieldCtx.Templates.Fields = {
        "ProspectRate": {
            "View": StatusFieldViewTemplate
        }
    };

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(statusFieldCtx);
})();

function StatusFieldViewTemplate(ctx) {



    if (ctx.CurrentItem.ProspectRate <=25)
    {
        return "<div background-image: url('<url of the pic>'');'>"+ctx.CurrentItem.ProspectRate +"</div>";
}}

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.