by Andreas

Sharepoint Designer – Custom Item Style

So you’ve started messing around in Sharepoint Designer creating your own custom styles for some Content Query Web part (CQWP) by altering existing or adding new code to ItemStyle.xsl. You reach a point where you want to display a field that you don’t see in use anywhere else and you start wondering how to reference it. This tiny piece of code will actually print out a list of all the fields that are passed through and are available:

<xsl:template name="ListAllAvailableFields" match="Row[@Style='ListAllAvailableFields']" mode="itemstyle">
   <xsl:for-each select="@*">
       :: <xsl:value-of select="name()" /><br />
   </xsl:for-each>
</xsl:template>

(Ensure you check in ItemStyle.xsl so the changes are reflected in your solution)

Open your CQWP in Edit mode, expand Presentation and change Item Style (under Style) to ListAllAvailableFields. Click Apply and you should now have a list of available fields printed neatly (..!) out for each list item.

image

 

These are the internal column names, and you can now reference any of them like this:

<div class="fancyLook">
    <xsl:value-of select="@MyCustomField" />
</div>

PS: the double colon ( :: ) in front of each field name is just added as a divider. Obviously this is not part of the name.

by Andreas

Sharepoint – use XSLT to define first element in CQWP

In a recent project I had the need for two Content Query Web Parts where one displayed the first 3 items from a list in a specific format, while the other had to display the remaining rows (from 4 and onwards) from the same list in a different format. Strangely enough I couldn’t find much useful information about this, but the solution was easy enough.

PS: For reasons not worth explaining, I solved this using two web parts but this could quickly be altered to be handled in a single CQWP.

The approach is to get the current row number, compare it to a value and decide whether or not to display the result. This was all done with XSLT in Sharepoint Designer.

1. Get the current row number

<xsl:variable name="RowNum" select="count(./preceding-sibling::*)" />

2. Add a simple IF statement to check if row number is higher than 3

<xsl:if test="$RowNum &gt; 3">
    <!-- whatever is in here will be rendered -->
</xsl:if>

I chose to use this to remove the first 3 elements of the result, but it can also be used to apply one style to the first X elements of a result and another style for the remaining elements.

There you have it, conditional filtering solved in Sharepoint Designer with OOTB functionality.

by Andreas

Sharepoint 2010 – Adding TaxonomyFieldControl to custom Page Layout

When attempting to add a taxonomy field control to your custom page layout, it will automatically be given a tag looking something similar to this:

<CustomTag_0:TaxonomyFieldControl FieldName="81d247d1-0373-4a2d-9e81-d4b69bf3e091" runat="server"></CustomTag_0:TaxonomyFieldControl>

When attempting to render this in Sharepoint Designer you’ll be told that “TagPrefix is not registered in this Web Form”:

image

If you’re one of those painfully optimistic characters you’ll still attempt to run it in the browser, which gives you the  ASP.NET error screen with the following message:

Parser Error Message: Unknown server tag ‘CustomTag_0:TaxonomyFieldControl”

For those who wants to dig even deeper than this, the following error message appears in the application event log:

Load control template file /_controltemplates/TaxonomyPicker.ascx failed: Could not load type ‘Microsoft.SharePoint.Portal.WebControls.TaxonomyPicker’ from assembly ‘Microsoft.SharePoint.Portal, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’.

 

The solution is simple: just add a reference to the assembly which contains the Taxonomy Picker control at the top of your Page Layout:

<%@ Register Tagprefix="Taxonomy" Namespace="Microsoft.SharePoint.Taxonomy" Assembly="Microsoft.SharePoint.Taxonomy, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

Then change the <CustomTag_0:TaxonomyFieldControl> to <Taxonomy:TaxonomyFieldControl> and off you go (remember there is a closing tag too, by the way..):

<Taxonomy:TaxonomyFieldControl FieldName="81d247d1-0373-4a2d-9e81-d4b69bf3e091" runat="server"></Taxonomy:TaxonomyFieldControl>