S4 vs. S5: multiselection

25 October 2005 /troniu 1 comments
in S4, a multiselection field, when queried, returned a string with concatenated GUIDs, separated by '|', and _terminated_ with '|'

in S5, the final '|' has gone with the side effect that a loop processing the GUIDs will ignore the last item in the case of a transformation as follows:


<xsl:template match="*" mode="main">
<xsl:variable name="ids" select="sc:fld('Trademark',.)"/>
<div class="trademarks">
<xsl:call-template name="PrintText">
<xsl:with-param name="ids" select="$ids"/>
</xsl:call-template>
</div>
</xsl:template>

<xsl:template name="PrintText">
<xsl:param name="ids"/>
<xsl:if test="$ids">
<xsl:variable name="itm_id" select="substring-before($ids, '|')"/>
<xsl:if test="$itm_id">
<xsl:variable name="itm" select="sc:item($itm_id,.)"/>
<xsl:value-of select="sc:fld('text', $itm)"/> 
</xsl:if>
<xsl:call-template name="PrintText">
<xsl:with-param name="ids" select="substring-after($ids, '|')"/>
</xsl:call-template>
</xsl:if>
</xsl:template>



the (pretty common) code above will fail for S5. The workaround is:

<xsl:template match="*" mode="main">
<div id="leftcol">
<xsl:call-template name="PrintSideDocument">
<xsl:with-param name="ids" select="sc:fld('leftsidedocuments',.)" />
</xsl:call-template>
</div>
</xsl:template>

<xsl:template name="PrintSideDocument">
<xsl:param name="ids"/>

<xsl:if test="$ids">
<xsl:variable name="itm_id" select="substring-before($ids, '|')"/>
<xsl:variable name="locID">
<xsl:choose>
<xsl:when test="$itm_id">
<xsl:value-of select="$itm_id"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$ids"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<xsl:variable name="itm" select="sc:item($locID,.)"/>
<xsl:if test="$itm">
<h3><xsl:value-of select="sc:fld('title', $itm)"/></h3>
<xsl:value-of disable-output-escaping="yes" select="sc:fld('teaser',$itm)"/>
<xsl:if test="$itm_id">
<hr />
</xsl:if>
</xsl:if>

<xsl:call-template name="PrintSideDocument">
<xsl:with-param name="ids" select="substring-after($ids, '|')" />
</xsl:call-template>
</xsl:if>
</xsl:template>

Creating custom Controls

4 October 2005 /troniu 0 comments
When you create a custom control, _do_not_ assign a namespace to the class that implements the control. Let it naked there, as follows:

using System.Configuration;
using System.Text;

///
/// Summary description for CustomFolderFiles.
///

public class CustomFolderFiles: Sitecore.ClientControls.ContentControl
{
#region Constants


Otherwise, when you try to register your class by defining a template field, Sitecore will concatenate the assembly name and the namespace and you'll have a hard time figuring out why you receive logged errors like

Could not find type in MainUtil.CreateObject: CustomFolderFiles

hth,
/p