SharePoint JSLink Question

I have been trying to create a simple JSLink Script that renders a image depending on what is selected in the Favorites field. I am relatively new to JS Link and may be making a simple syntax error. Any guidance is greatly appreciated.

at this time I am getting no response. I have written jslink before so its not a js location problem.


(function () {
 
     
    var Context = {};
    Context.Templates = {};
    Context.Templates.Fields = {
       
        "Favorites": { "View": FavoritesTemplate }
    };
 
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(Context);
 
})();
// I have a field named Favorites its a choice field with Yes and No
function FavoritesTemplate(ctx) {
 
    var FavoritesField = ctx.CurrentItem.Favorites;
    var image = "";
 
    // Select the image source
    if (FavoritesField == "Yes"){
        image = "~site/ALL%20Images/goldstar.png";
    }
    else if (FavoritesField == "No"){
        image = "~site/ALL%20Images/emptystar.png";
    }
    else{
        image = "~site/ALL%20Images/skull.png";
    }

    return "<img src = '" + image + "'/>";
   
}


September 6th, 2015 6:01pm

Your code runs fine in my tests. Check to see if the URL to the JS link file is correct. Mine was to "~site/_catalogs/masterpage/test.js".

Did you save it to the master pages gallery and set the JavaScript Display Template content type? Here's what my test looked like:

Free Windows Admin Tool Kit Click here and download it now
September 7th, 2015 12:33am

Hello,

make sure you are using the correct url while referencing the js file and images...

and u can try

 var FavoritesField = ctx.CurrentItem["Favorites "] in place of

 var FavoritesField = ctx.CurrentItem.Favorites;

Hope this will help...

Mark as answer if you find it helpful............

September 7th, 2015 1:02am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics