Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

SharePoint JSLink Question

$
0
0

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 + "'/>";
   
}



Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>