mel

Search



Audience-Targeted Announcements in SharePoint

We all know about the potential behind SharePoint’s audience targeting feature in MOSS 2007. But, as with most things SharePoint, it leaves a bit to be desired. You can enable audience targeting on a list in SharePoint, add a Content Query Web Part to that list on a page, then filter the list by audience by selecting the appropriate options in the Tool Pane. However, if you’ve ever tried to do this with an Announcements list, you have probably found that Microsoft left the bulk of that one for us to do.

01

So, what am I talking about? Well, let’s take a look: create an announcements list with audience targeting enabled and add a Content Query Web Part to your page, then adjust the settings of the Tool Pane so that the announcements list is displayed, like so:

clip_image002

Be sure to also set your expiration filter and sort your list appropriately. Under ‘Additional Filters,’ select ‘Expires’ from the drop-down list under “Show items when.’ Select ‘is greater than or equal to’ from the second drop down list and select the radio button for ‘[Today].’ Then sort by the created date in descending order.

At this point, if you hit the Apply button, everything appears to be working correctly, as a list of targeted announcements are displayed in the Web Part view. But, if you scroll further down the Tool Pane and open up the Item Style drop-down list under Presentation, you won’t find a style for an Announcements list. Bummer. Now, if you are fine with a list of links that display only the title of your announcements, then you don’t need to go any further. However, if you’re like me and you want your announcements to look at least something like the regular Announcements Web Part, then you will need to do a little more work (don’t shoot the messenger).

Actually, it’s not that bad, but you are going to have to edit the ItemStyle.xsl file located in the Style Library (under XSL Style Sheets) of your site collection, which can blow things up if you’re not careful. Don’t fret – just be careful :) .

Open SharePoint Designer and navigate to the Styles Library at the root of the site collection. Open the XSL Style Sheets folder and double-click the ItemStyle.xsl file to open it. On about line 48, give or take, you should see a template named ‘NoImage.’ Insert the following code just above this template:

<xsl:template name=”Announcements” match=”Row[@Style='Announcements']” mode=”itemstyle”>
  <div style=”font-size: 12px; margin: 5px 5px 5px 5px”>
    <span style=”float: right; color: #666666; font-size: 11px”><xsl:value-of select=”@Created” /></span>
    <strong style=”color: #cc0000;”><xsl:value-of select=”@Title”/></strong><br />
    <div style=”font-size: 11px; color: #666666;”><xsl:value-of select=”@Body” disable-output-escaping=”yes” /></div>
  </div>
</xsl:template>

clip_image003

You can go in and adjust the inline styles a bit, if you want. Now, save the file, close it, and check it back in (publish a major version).

Go back to your Web Part page and modify the Content Query Web Part. Scroll down to Item Style and open the drop-down list. If all went well, you should now see an entry for Announcements. Select Announcements and hit Apply.

WHAT?! – you say – this still doesn’t look right. Don’t worry, we still have one last thing to do. We have to “tell” SharePoint about the other fields that we want displayed along with the title. Click on the drop-down menu for the Web Part and select Export.

Save the Web Part somewhere, then open it in SharePoint Designer. We are going to be editing the property tag name CommonViewFields. Add ‘Body, text; Created, text’ to the tag so it looks like the following:

<property name=”CommonViewFields” type=”string”>Body, text; Created, text</property>

Save the Web Part and import it back onto your page, drag and drop it into place, then remove the old Web Part. Publish and you are done. You also now have a custom Web Part that you can reuse anywhere in your site collection.

Posted by melyssa Posted in: SharePoint No Comments » May 2008