Question

In a publishing site, I want to create a webpart that display the result of a query with a custom display (a kind of rotator).

As the goal of the web part is to be reusable and must be quite simply configurable by the user, I'm wondering what are the pros and cons of the following approaches :

  • custom web part that produces the html in a "hard-coded" way. Add tool pane to allow the user to setup data
  • content query web part with a xslt transformation
  • silverlight web part with a custom option pane within the webpart

I feel the 2nd solution may be better because the whole setup of the webpart is already here, but I fear a bit the xslt will be quite painful.

thanks in advance for your feedbacks

Was it helpful?

Solution

Don't be afraid of XSLT. This is going to give you a tremendous amount of power without having to develop or deploy anything in return for a little effort to understand it. I always recommend starting with an identity transform so that you can see the XML that is coming in, and then start adding templates to process the nodes you are interested in.

Visual Studio has great tooling for working with XSLT. You can create an intitial XSLT with an identity transform and then use it to transform a source XML file (corresponding to your list data). You can then start the transformation in debug mode and breakpoint and step through your XSLT.

Having said that, there are cases where writing a custom web part makes sense. There may be something you need that CQWP can't do, or the CQWP solution may be very convoluted in some cases. That's something you have to decide from understanding the problem. But don't avoid CQWP because of XSLT.

OTHER TIPS

For your case, i.e. displaying results with custom display, i would recommend two options:

  1. Transform results on client side, for example if you use some kind of jQuery plugin for Rotator, it would be possible to initialize results data for Rotator with jQuery.
  2. The option with extending the CQWP, in that case you could customize the rendering of results, for example see my blog Rendering Content Query Web Part results in Table Layout about how to arrange items in Plain Old Table Layout instead of List Layout

Another option, expanding on Bill(SPDoctor)'s answer, is to extend the CQWP, by creating a new class for your web part that inherits from ContentByQueryWebPart.

This will let you add more options to the toolpane to control the logic, as well as make custom methods available in your XSLT, which you can write "code-behind" for in your webpart's class.

Waldek Mastykarz has covered this in a series of excellent blog posts on this site: http://blog.mastykarz.nl/extending-content-query-web-part-with-custom-data/

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top