May be MDS is enabled on your SharePoint site. In this case you will need to use RegisterModuleInit() function.
You need to do two modifications to achieve this.
First, you need to change the anonymous entry point function to a function with an entry point signature. Then, you need to call RegisterModuleInit() function to register an override of this code on MDS enabled sites.
For example:
RegisterModuleInit("CSRAssets/CSRFieldType.js", RegisterFavoriteColor); // CSR-override for MDS enabled site
RegisterFavoriteColor(); //CSR-override for MDS disabled site (because we need to call the entry point function in this case whereas it is not needed for anonymous functions)
function RegisterFavoriteColor() {
var favoriteColorContext = {};
// You can provide templates for:
// View, DisplayForm, EditForm and NewForm
favoriteColorContext.Templates = {};
favoriteColorContext.Templates.Fields = {
"FavoriteColorField": {
"View": favoriteColorViewTemplate
}
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(
favoriteColorContext
);
}
// The favoriteColorViewTemplate provides the rendering logic
// the custom field type when it is displayed in the view form.
function favoriteColorViewTemplate(ctx) {
var color = ctx.CurrentItem[ctx.CurrentFieldSchema.Name];
return "<span style='background-color : " + color +
"' > </span> " + color;
}
Reference: https://blogs.msdn.microsoft.com/sridhara/2013/02/08/register-csr-override-on-mds-enabled-sharepoint-2013-site/