如何在 SharePoint 的公告中创建指向该段落其余部分的链接,该链接显示以下文字:阅读更多
干杯
我发现最干净、最简单的方法是在 ItemStyle.xsl 中创建一个模板,该模板选择公告正文内容的子字符串,并在下方显示文章本身的链接。
将以下代码添加到您的 ItemStyle.xsl 文件(在 SharePoint Designer 中导航到“样式库/XSL 样式表”文件夹)后,您可以通过浏览器修改 Web 部件,并将项目样式(演示/样式)更改为'阅读更多公告'。此代码将显示的字符数保持为 190 个字符(请参阅 substring($bodyContent,1,190 函数调用)。
<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="bodyContent">
<xsl:call-template name="removeMarkup">
<xsl:with-param name="string" select="@Body"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="substring($bodyContent,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>
这绝对应该有效,并且非常容易实现。