Sign In
The Sug > Blogs > // todo: be awesome > Posts > Secured "Summary Links" Web Part
October 14
Secured "Summary Links" Web Part

Have you ever needed to display links on a page for certain groups of people?  Have you ever thought, "Hey, why can't I secure the links in this summary links web part?"  You are not alone.

While you could accomplish this with some custom code, it can be done OOTB with a links list and a content query web part (CQWP). 

The list is straight forward. Just create a list based on the Links template and secure the list itself or each individual item as required.  The content query web part will need a little massaging to display the links properly.

First, you will need to export a baseline CQWP and add the URL field to the common view fields so you can access it via the XSLT.  You will also need to set the UseCopyUtil property to false.  This will enable the XSLT templates that build item url's to use a custom field rather than a default value.


<property name="CommonViewFields" type="string">URL,URL</property>
<property name="UseCopyUtil" type="bool">False</property>



Import that back into the web part gallery (or don't... you can always just import it onto a page) and then add it to a page.  Setup the web part so it only gets Links list items (set the list type to Links and the content type to Link). 

Next you need to add a new item style to handle the links. You will need to modify the ContentQueryMain.xsl file and the ItemStyle.xsl file (both in the XSL Style Sheets folder of the Style Library). 

You need to add a template to the ContentQueryMain.xsl file that gets the title from a URL field value.  A URL field value stores the url and the title as a comma separated string, so something like this will work:



<xsl:template name="OuterTemplate.GetUrlFieldValueTitle">
  <xsl:param name="Value" />
  <xsl:if test="not(contains($Value,', '))">
            <xsl:value-of select="$Value"/>
  </xsl:if>
  <xsl:if test="contains($Value,', ')">
      <xsl:call-template name="OuterTemplate.Replace">
                <xsl:with-param name="Value" select="substring-after($Value,', ')"/>
                <xsl:with-param name="Search" select="',,'"/>
                <xsl:with-param name="Replace" select="','"/>
      </xsl:call-template>
  </xsl:if>
</xsl:template>



You then need to add the new item style template to the ItemStyle.xsl file.  The example below just displays each link on a line with the notes below it.  Obviously, this can be changed to any style you need.  The important thing is to set the DisplayTitle variable to the value from the new template above and the SafeLinkUrl to use the URL column.



<xsl:template name="Links" match="*" mode="itemstyle">
        <xsl:variable name="SafeLinkUrl">
            <xsl:call-template name="OuterTemplate.GetSafeLink">
                <xsl:with-param name="UrlColumnName" select="'URL'"/>
            </xsl:call-template>
        </xsl:variable>
        <xsl:variable name="DisplayTitle">
            <xsl:call-template name="OuterTemplate.GetUrlFieldValueTitle">
                <xsl:with-param name="Value" select="@URL"/>
            </xsl:call-template>
        </xsl:variable>
        <div id="linkitem" class="item">
            <div class="link-item">
                <a href="{$SafeLinkUrl}" title="
{@LinkToolTip}">
                    <xsl:value-of select="$DisplayTitle"/>
                </a>
                <div class="description">
                    <xsl:value-of select="@Comments" />
                </div>
            </div>
        </div>
</xsl:template>
 



Finally, just set the item style of the CQWP to the new Links style and save the web part.

You now have a secured links web part!

Comments

There are no comments for this post.