I have a blog site in sharepoint 2013, I wanted to use Javascript Template for displaying the Post in a custom style.
Here is how my js file looks like.
(function () {
var overrideCtx = {};
overrideCtx.Templates = {};
overrideCtx.Templates.Fields = {'Body':{'View': CBody}};
alert("CSR Registered");
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
})();
function CBody(ctx) {
var ret = ctx.CurrentItem.Body + "<b>" +
"<button onclick='alert("template working");'>Test Button</button>" + "</b>" ;
return ret;
}
But When I use the file in JSLink of the Post Page (SiteCollection/sites/test/Lists/Posts/Post.aspx?ID=160)
I am unable to see the changes, the CSR is not getting registered and page is not displaying any errors.
In other Custom List I tried a similar approach, In the list I created a custom view and applied the JSLink template it worked fine however on the default AllItems View it failed to display the Custom template.
Can't we apply CSR on default views?. Help me solve this issue.