Item Style XSL - Showing Read More Link When Content Is Cut Off
-
29-09-2020 - |
Question
I have managed to create an ItemStyle template for my CQWP. It pulls from various announcements. I have set the character limit to 400 and placed a link at the end where a user can click to view the full announcement. However, this displays on all announcements, regardless of length.
How can I set it to where the link only shows when the announcement is cut off / over 400 characters?
Here is my XSL:
<table>
<tr><td>
<xsl:variable name="SafeLinkUrl">
<xsl:call-template name="OuterTemplate.GetSafeLink">
<xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
</xsl:call-template>
</xsl:variable>
<h3><a href="{$SafeLinkUrl}"><xsl:value-of select="@MyTitle"/></a></h3>
</td></tr>
<tr><td>
<xsl:variable name="SafeLinkUrl">
<xsl:call-template name="OuterTemplate.GetSafeLink">
<xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of disable-output-escaping="yes" select="substring(@MyDesc,1,400)" /> - <a href="{$SafeLinkUrl}">[Full Announcement]</a><br /></td></tr>
<tr>
<td>
</td>
</tr>
</table>
Solution
You'd want to wrap that in an if, something along the lines of this:
<xsl:if test="string-length(@MyDesc) > 400">
<xsl:value-of disable-output-escaping="yes" select="substring(@MyDesc,1,400)" /> - <a href="{$SafeLinkUrl}">[Full Announcement]</a><br />
</xsl:if>
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange