Awkward SharePoint Link field text

I had a gnarly support call today. One of our customers was using Announcement lists to display news on the homepage of their intranet, and they’ve a thumbnail image they’d set for each item. Then, on the home page, they’ve got a Content Query Web Part using some custom XSL to render those announcements.

However, the Content Query Web Part would only show some of the thumbnail images.Capture

TL;DR – Saving an image field on a ‘New’ form without a descripion saves a different format to after an ‘Edit’, which sets a default even if you don’t change the image field value.

Continue reading “Awkward SharePoint Link field text”

Advertisements
Awkward SharePoint Link field text

CQWP and Discussions

Hmm. Interesting problem – I had a Content Query Web Part (CQWP) that was displaying the Title for Discussions. Unfortunately when you clicked on them, they took you to the display form for the start of the thread, not the entire thing:

Okay, but could I get it to link to a view of the discussion thread itself?

Continue reading “CQWP and Discussions”

CQWP and Discussions

Disable Output Escaping in XSL

Really, just a reminder for myself, but if you work with SharePoint long enough you’re bound to end up using something like the Content Query Web Part or a Data View Web Part to aggregate and output a rich text source – but all your HTML gets escaped, so it appears content on the page.

The command you want is DisableOutputEscaping:

<xsl:value-of select="somevalue" disable-output-escaping="yes" />

This will cause the HTML to be output unescaped – i.e. as HTML.

Side note: Sometimes people want things like the CQWP to show the first part of the content as a ‘summary’. This trucating content to display in the CQWP or DVWP is difficult; either a) you risk having unfinished tags in the HTML you do emit, or b) you have to strip out all HTML, which can ruin your formatting. a) is a particular problem, as unfinished <table> tags can cause all sorts of weirdness on page.

My preferred option is to have a additional ‘summary text’ box that accepts plain text, and have the author generate the summary manually. That way we avoid outputting HTML like that entirely.

Disable Output Escaping in XSL

Newsticker Web Part for SharePoint

I’ve written a web part that provides a ‘newsticker’ for SharePoint, although it’ll actually query for news, documents, or anything else you can query for with the Content Query Web Part (CQWP). In fact, it’s just a configuration of the CQWP, which also uses jQuery for animation and stuff. Typically web sites use this for displaying news or announcements, but you can use it to query for any SharePoint content type(s), as you would with the Content Query Web Part.

The Content Query Ticker Web Part looks like this in operation…

$(document).ready(function(){$(“#demoTicker”).cqticker(4000);});

  • Group 1 : Item A – Some Description
  • Group 1 : Item B – Some Other Description
  • Group 2 : Item C – Yet Another Description

It does require MOSS 2007, and you do need to enable the Publishing Infrastructure on your site collection.

For more details, see this page.

Newsticker Web Part for SharePoint

CQWP: Show the first item in each group

So, we have a customer who has a library of Newsletters.

library-of-newsletters

These newsletters belong to different regions, and they have a date on which they should be ‘published’ – or at least, a date at which they’re the most recent item. So, we have two columns to capture that – News Region and Publish Date.

The customer wanted a web part on a page that would show the most recently ‘published’ item for each of those regions. Something like:

result

I did this with the Content Query Web Part (CQWP) – but how?

Well, first I set my CQWP to query the list of newsletters. They have a specific content type that I queried for. I filtered items with a Publish Date in the future out – although not a secure way of preventing users seeing these items, at least it doesn’t make the obvious.

Next, I set the CQWP to group by News Region, and Sort by descenting Publish Date. So far, so standard – but it would also return multiple items for each region, and display their title, not their region.

This called for a special Itemstyle, which I added using the technique mentioned before for putting ItemStyles into a different file. This made sense; we’re not going to use this style extensively, so it’s best to keep it separate.

Next, I modified my CommonViewFields to bring in the News Region column. I’ve mentioned this before.

Then I wrote my XSL:

xsl

Take a look at it – it’s cool.

Looking at the code, you can see I read the News Region that we’re looking at into a variable. I then count up the number of preceding nodes which also have the same value for their News Region.

The first node with a particular News Region value will always be the one with the latest Publish Date that isn’t in the future – therefore, the most recent one for that region. The count statement won’t count nodes for other regions, either. So, if it’s the first, we display it – using the News Region text, rather than the title. Simple!

(But a bugger of an XSL query to figure out)

CQWP: Show the first item in each group

Link the CQWP to another XSL File

I was going to remind myself of a technique that I’d seen Liam Cleary use on his blog about importing XSL files into ItemStyles.xsl, but then I noticed that he’d linked to a far better idea from Brendon Swartz – you can change the XSL file that the Content Query Web Part presents ItemStyles for. If you export the Content Query Web Part as an XML file and edit it, you’ll see a property ItemXslLink. Simply give it a url to the new ItemStyles.xsl file.

Personally, I think this is fantastic. Frequently I have been asked to do custom roll-up of content, with customised display. If you have to add to the standard ItemStyles.xsl, then before long your ‘Presentation’ setting for your standard CQWPs is full of highly specific item styles. This way, I can isolate – nearly hide – the existance of my much more specific item styles to general users.

And I’ll say more about what I was doing with it shortly.

Link the CQWP to another XSL File