CQWP: 30 Tips #5

I mentioned before that the SP 2010 CQWP automatically creates the available slots by parsing your .xsl and creating a slot for all the @Variables it comes across.  When you dig into the item style though you may notice the presence of several @Variables in the out of the box templates that get no slot, such as @OpenInNewWindow

<a href=”{$SafeLinkUrl}” title=”{@LinkToolTip}”>
              <xsl:if test=”$ItemsHaveStreams = ‘True’”>
                <xsl:attribute name=”onclick”>
                  <xsl:value-of select=”@OnClickForWebRendering”/>
                </xsl:attribute>
              </xsl:if>
              <xsl:if test=”$ItemsHaveStreams != ‘True’ and @OpenInNewWindow = ‘True’”>
                <xsl:attribute name=”onclick”>
                  <xsl:value-of disable-output-escaping=”yes” select=”$OnClickTargetAttribute”/>
                </xsl:attribute>
              </xsl:if>
              <xsl:value-of select=”$DisplayTitle”/>
           </a>

If you scroll all the way down in ItemStyle.xsl, you’ll find the hidden template that does this:

<xsl:template name=”HiddenSlots” match=”Row[@Style='HiddenSlots']” mode=”itemstyle”>
    <div class=”SipAddress”>
      <xsl:value-of select=”@SipAddress” />
    </div>
    <div class=”LinkToolTip”>
      <xsl:value-of select=”@LinkToolTip” />
    </div>
    <div class=”OpenInNewWindow”>
      <xsl:value-of select=”@OpenInNewWindow” />
    </div>
    <div class=”OnClickForWebRendering”>
      <xsl:value-of select=”@OnClickForWebRendering” />
    </div>
  </xsl:template>

If you find that you want to make these available in your slots, which can be handy for LinkToolTip or OpenInNewWindow, you can simply remove them from the HiddenSlots template.

Share:
  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • LinkedIn
  • Reddit
  • RSS

CQWP: 30 Tips #4

In the last tip, I told you that CQWP would populate several fields for you and I gave you an item template that would spit them out for you.  What I left out is that CQWP also populates a number of variables for you (variables are referenced with a $ instead of the @).  These variables are handed into your .xsl as parameters, not through the .xml.  Consequently, there is no easy itemstyle that will just enumerate them all.  Instead, you can see them all defined as parameters in the ContentQueryMain.xsl .

<xsl:param name=”cbq_isgrouping” />
    <xsl:param name=”cbq_columnwidth” />
    <xsl:param name=”Group” />
    <xsl:param name=”GroupType” />
    <xsl:param name=”cbq_iseditmode” />
    <xsl:param name=”cbq_viewemptytext” />
    <xsl:param name=”cbq_errortext” />
    <xsl:param name=”SiteId” />
    <xsl:param name=”WebUrl” />
    <xsl:param name=”PageId” />
    <xsl:param name=”WebPartId” />
    <xsl:param name=”FeedPageUrl” />
    <xsl:param name=”FeedEnabled” />
    <xsl:param name=”SiteUrl” />
    <xsl:param name=”BlankTitle” />
    <xsl:param name=”BlankGroup” />
    <xsl:param name=”UseCopyUtil” />
    <xsl:param name=”DataColumnTypes” />
    <xsl:param name=”ClientId” />
    <xsl:param name=”Source” />
    <xsl:param name=”RootSiteRef” />
    <xsl:param name=”CBQPageUrl” />
    <xsl:param name=”CBQPageUrlQueryStringForFilters” />
  <xsl:variable name=”BeginList” select=”string(‘&lt;ul class=&quot;dfwp-list&quot;&gt;’)” />
  <xsl:variable name=”EndList” select=”string(‘&lt;/ul&gt;’)” />
  <xsl:variable name=”BeginListItem” select=”string(‘&lt;li class=&quot;dfwp-item&quot;&gt;’)” />
  <xsl:variable name=”EndListItem” select=”string(‘&lt;/li&gt;’)” />

Share:
  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • LinkedIn
  • Reddit
  • RSS

CQWP: 30 Tips #3

By default, CQWP retrieves quite a few fields.  These are fields that the web part sets for you. They don’t require any additional action by your user when the web part is added to the page.  The problem is they aren’t documented anywhere that I’ve ever come across.  Enter this trick from SP 2007’s CQWP:

Inside your ItemStyle.xsl, add this new template:

<xsl:template name=”FieldIdentifier” match=”Row[@Style='FieldIdentifier']” mode=”itemstyle”>
        <table>
            <tr>
                <td>——————–</td>
            </tr>
            <xsl:for-each select=”@*”>
                <tr>
                    <td>
                <xsl:value-of select=”name()” /> – <xsl:value-of select=”.” />
            </td>
                </tr>
            </xsl:for-each>
        </table>
    </xsl:template>

Then select FieldIdentifier in your CQWP as the item style.  For every record matching your query, it will spit out every available field in the xml.  The result is ugly, but extremely useful.

image

Did I mention it was ugly?  If you’re stuck in an SP 2007 environment (pre-SP2010’s Slots), you’ll use that template a lot.

Share:
  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • LinkedIn
  • Reddit
  • RSS

CQWP: 30 Tips #2

Following from Tip #1, when you create your custom .dwp.  Do as little configuration as possible to the out of the box (OOTB) CQWP before exporting it.  I usually just add the OOTB CQWP to a page, then go into its appearance tab to update its web part title to  Contoso Content Query or PM Content Query before exporting it.  This way, when you add it back into the site collection’s web part gallery it’s as close to the original as possible.

Share:
  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • LinkedIn
  • Reddit
  • RSS

CQWP: 30 Tips #1

I’m speaking March 8 at the 2012 Heartland Region SharePoint Conference (http://iccsharepoint.com).  My presentation, titled “CQWP, The Most Powerful Tool You’re Underutilizing.” will be a deep dive into the CQWP covering how to use it and how to customize it.  I hope to show why I think CQWP is one of the most powerful tools available to a SharePoint dev. 

In honor of the upcoming presentation, I’m going to post 30 CQWP tips.  I had this idea a little while ago, but do to the power of procrastination, I now have exactly 30 days until the conference. 

If you haven’t registered yet, you can still do so at http://iccsharepoint.com, but seats are filling up fast.

On to the post: 3 xsl files go into creating the CQWP’s layouts.  ItemStyle.xsl controls the available item layouts, Header.xsl controls the available group layouts, and ContentQueryMain.xsl acts as the broker that lays down the foundation and calls out to the header and item styles as needed.  To customize a CQWP layout, you’ll need to create copies of one or more of these .xsl files and then update a CQWP’s .dwp (.webpart) to reference your copies.

Here’s my typical working scenario.  As early as possible, if I identify the need for a CQWP in a site collection, I’ll create copies of the .xsl files.  I’ll create the copies side by side with the originals but name them according to the client (Contoso_ItemStyle.xsl, Contoso_Header.xsl, Contoso_ContentQueryMain.xsl).  If I have something more specialized, such as a set of styles in mind for use in a project management collection, I may name them something like PM_ItemStyle.xsl, PM_Header.xsl, PM_ContentQueryMain.xsl.  Then I’ll create a new .dwp (.webpart) that references the new .xsl files and upload it to the webpart gallery, named something like Contoso CQWP (or PM CQWP).

Tip #1:  Although you’re immediate customization need may only require updates to one of the 3 .xsl files. I recommend you ALWAYS copy all 3 and make reference to them in the .dwp. By doing so, you can make changes in the other two as needed later on without having to create a new .dwp. Thus your future changes will be available to your existing CQWPs (as long as you based them on your updated .dwp).

Share:
  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • LinkedIn
  • Reddit
  • RSS