I have written a JSlink for custom display of my announcement web part. JSlink is working fine and i can see the results.
Now my customer wants to place 2 different announcement web parts in one page and want to see the same custom display for both of them.
I know that i can solve this issue either using the list name or the view name.(I google this and found many article about it)
but here is the problem. I don't want to hardcode any value in the JSlink as I want other people from the same site collection (different sub-site under site collection) also use the same jslink for there own Announcement web parts. They can give any name to there announcement list.
kindly help.
here is the code:
(function () {
(window.jQuery || document.write('<script src="../SiteAssets/Javascripts/Announcements/jquery.js"><\/script>'));
function CustomAnnouncementItem(ctx)
{
if ((ctx.ListTitle == "General Announcements") || (ctx.ListTitle == "HR Announcements") || (ctx.ListTitle == "Team Announcements") || (ctx.ListTitle == "Announcements"))
{
ctx.BaseViewID = 90;
var bodyValue = ctx.CurrentItem.Body;
var _announcementID = ctx.CurrentItem.ID;
var regex = /(<([^>]+)>)/ig;
bodyValue = bodyValue.replace(regex, "");
var newBodyValue = bodyValue;
var ret = "";
ret += "<div style='Padding:3px;border:1px solid #87CEFA;margin:5px'><b>" + ctx.CurrentItem.Title + "</b><br>"
if (bodyValue && bodyValue.length >= 100)
{
newBodyValue = bodyValue.substring(0, 100) + " <a href='" + ctx.displayFormUrl + "&ID=" + _announcementID + "'>Read More...</a>";
ret += newBodyValue + "</div>";
}
else
{
ret += newBodyValue + "</div>"
}
return ret;
}
else
{
return RenderItemTemplate(ctx);
}
}
var overrideAnnouncementCtx = {};
overrideAnnouncementCtx.Templates = {};
overrideAnnouncementCtx.Templates.Header = " ";
overrideAnnouncementCtx.Templates.Footer = " ";
overrideAnnouncementCtx.Templates.Item = CustomAnnouncementItem;
overrideAnnouncementCtx.ListTemplateType = 104;
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideAnnouncementCtx);
})();