I would like to override a field with an image using the value of another field. So, I have an image library and the Name field captures the name of the image file. I also have a Hyperlink or Picture field.
I want to override the pic field with the Name field but it's not working. name is undefined.
I know the concept works because if I hard code a static image, the image shows.
(function() {
var nameFieldContext = {};
nameFieldContext.Templates = {};
nameFieldContext.Templates.Fields = {
"pic": {"View": renderImageToRate }
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(nameFieldContext);
})();
function renderImageToRate(ctx){
alert("In function");
var name = ctx.CurrentItem.Name;
return "<img src='"+name+">";
}
Any ideas?
src
attribute. passing just file name will not work. try my suggestions given below. let me know if it works for you.