Question

Created by field is formatted as "name". Field ref used in jslink ctx override is:

 ...<span>Submitted by: " + ctx.CurrentItem.Author + "</span>...

Field is present in view but all I get is "object Object". It does work when list body only is formatted, so seems to be related to formatting the header element.

Update:

(function () {


var overrideCtx = {};
overrideCtx.Templates = {};


overrideCtx.Templates.Header = "<div class='slider3'>";
overrideCtx.Templates.Footer = "</div>";



//       Register the template overrides.

SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);

})();


function CustomItem(ctx) {

var ret = "<div class='slide'><a target='_blank' href='/cookbook/Lists/Posts/Post.aspx?ID=" + ctx.CurrentItem.ID + "'>"
 + ctx.CurrentItem.Image_x0020_upload + "<h5 class='event-title'>" + ctx.CurrentItem.Title + "</h5></a><span>Submitted by: "
 + ctx.CurrentItem.Author + "</span><br />" + ctx.CurrentItem.Body + " </div>";
return ret;
}
Was it helpful?

Solution

I just did a quick test, and it seems like ctx.CurrentItem.Author is actually an array:

enter image description here

So you might want to try this:

...<span>Submitted by: " + ctx.CurrentItem.Author[0].title + "</span>...

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top