TwitterLinkedInBlog

Saturday, March 28, 2009

SP2007 - How to hide a CQWP Group Header if it is Blank

By default, the CQWP Group Header displays (Blank) if the group by field is null. The desired behavior is to display nothing.

For example, add the following xsl template, SmallTextHiddenBlank, under the existing xsl template, SmallText, in the Header.xsl file in the Style Library. Then, choose the SmallTextHiddenBlank Header template in the CQWP Tool Part.

<xsl:template name="SmallTextHiddenBlank" match="*[@GroupStyle='SmallTextHiddenBlank']" mode="header">
  <xsl:choose>
    <xsl:when test="string-length(normalize-space(@*[name()=$Group])) = 0">
    </xsl:when>
    <xsl:otherwise>
      <div class="groupheader item small">
      <xsl:call-template name="OuterTemplate.GetGroupName">
        <xsl:with-param name="GroupName" select="@*[name()=$Group]"/>
        <xsl:with-param name="GroupType" select="$GroupType"/>
      </xsl:call-template>
      </div>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

Tuesday, March 10, 2009

SP2007 - How to Programmatically Inherit Current Navigation

Scenario: Office SharePoint Server Publishing Infrastructure is activated at the SPSite level. Office SharePoint Server Publishing is NOT activated at the SPWeb level. Attempting to inherit Current Navigation from the Parent SPWeb.

using Microsoft.SharePoint.Publishing;
  …
  PublishingWeb currentPublishingWeb = PublishingWeb.GetPublishingWeb(currentWeb);
  currentPublishingWeb.InheritCurrentNavigation = true;
  currentPublishingWeb.Update();

 // Does not work because the SPWeb is NOT a PublishingWeb:
 //if (PublishingWeb.IsPublishingWeb(currentWeb))
 //{
 //    PublishingWeb currentPublishingWeb = PublishingWeb.GetPublishingWeb(currentWeb);
 //    currentPublishingWeb.InheritCurrentNavigation = true;
 //    currentPublishingWeb.Update();
 //}
 //else
 //{
 //    currentWeb.Navigation.UseShared = true;
 //    currentWeb.Update();
 //}