I have added CSWP to a page which retrieves 5 recent posts from a community site. Now I want to modify display template to show the thumbnail of the user who created the post. Is it possible?
If you're bulding your own custom template, get hold of one of the templates from the '_catalogs\masterpage\Display Templates' and modify it.
Inside ManagedPropertyMapping add an Author property.
Then within your template you could use something like:
ms_outHtml.push(' ' ,' <img class="authorImage" src="/_layouts/15/userphoto.aspx?size=S&accountname=', ctx.CurrentItem.Author , '" />' );
You might also be able to simply map an Author property and use PicureURL of the built in templates from the search web part properties.
(My account is new so I have to 'answer' instead of comment. Don't accept this as the answer since I'm just expanding on Aveenav's suggestion.)
Try using ctx.CurrentItem.Author.email So in my TemplateOverrides for Item, I do something like...
return '<img src="/_layouts/15/userphoto.aspx?size=S&accountname=' + ctx.CurrentItem.Author.email + '"/>';
... and this works just fine for me. Even with size=S, I needed to force the size with something like
style="width:64px; height: auto;"
inside my img tag.