0

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>
  • Is there a way to show a "Show More" link when you only want to display, say, 3 items at time? – PeterX Oct 27 '15 at 8:01
1

You'd want to wrap that in an if, something along the lines of this:

<xsl:if test="string-length(@MyDesc) &gt; 400">
<xsl:value-of disable-output-escaping="yes" select="substring(@MyDesc,1,400)" /> - <a href="{$SafeLinkUrl}">[Full Announcement]</a><br />
</xsl:if>
  • 1
    That works! I had to put it before the start of the link or it would hide all the articles that were less than 400 characters. <xsl:value-of disable-output-escaping="yes" select="substring(@MyDesc,1,400)" /> <xsl:if test="string-length(@MyDesc) &gt; 400"> - <a href="{$SafeLinkUrl}">[Full Announcement]</a><br /> </xsl:if> – Jim Jul 23 '14 at 17:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.