I want to add Read more link in my Announcement Web Part I followed this blog post: http://www.learningsharepoint.com/2013/04/07/styling-announcements-with-javascript-using-js-link-in-sharepoint-2013/
I created an external javascript file and put the blow Javascript code:
(function () {
var itemCtx = {};
itemCtx.Templates = {};
itemCtx.Templates.Header ="<div><b>Announcements</b></div><table>";
itemCtx.Templates.Item = ItemOverrideFun;
itemCtx.Templates.Footer = "</table>";
itemCtx.BaseViewID = 1;
itemCtx.ListTemplateType = 104;
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(itemCtx);
})();
function ItemOverrideFun(ctx) {
var _announcementTitle = ctx.CurrentItem.Title;
var _announcementDesc = ctx.CurrentItem.Body;
var _announcementID = ctx.CurrentItem.ID;
return "<tr><td><p><b>"+_announcementTitle+"</b></p>"+_announcementDesc+"<a href='/sites/testdev/Lists/Announce/DispForm.aspx?ID='+_announcementID +'>Read More...</a> </td></tr>";
}
when I put the link inside JS Link it doesn't work
i have also tried another blogs post with the blow codes which I have putted in my ItemStyle.xsl but it also does not works.
<xsl:template name="removeMarkup">
<xsl:param name="string" />
<xsl:choose>
<xsl:when test="contains($string, '<')">
<xsl:variable name="nextString">
<xsl:call-template name="removeMarkup">
<xsl:with-param name="string" select="substring-after($string, '>')" />
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="concat(substring-before($string, '<'), $nextString)" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$string" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="ReadMoreAnnouncements" match="Row[@Style='ReadMoreAnnouncements']" mode="itemstyle">
<br />
<div class="RMAnnouncementsTitle">
<xsl:value-of select="@Title" />
</div>
<div class="RMAnnouncementsBody">
<xsl:variable name="body">
<xsl:call-template name="removeMarkup">
<xsl:with-param name="string" select="@Body"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="substring($body,1,190)" />
...
<br />
<a>
<xsl:attribute name="href">
/Lists/Announcements/DispForm.aspx?ID=
<xsl:value-of select="@ID">
</xsl:value-of>
</xsl:attribute>
<xsl:attribute name="class">
RMAnnouncementsMoreLink
</xsl:attribute>
read more
</a>
</div>
</xsl:template>