14 September 2006

using Sitecore.Kernel.Webutils

Webutils functions can be used as helper functions as well. In order to get the url of the server, we can use it as follows:

install it in web.config:

<xslExtensions>
...
<extension mode="on" type="Sitecore.Web.WebUtil, Sitecore.Kernel" namespace="http://www.sitecore.net/webutil" singleInstance="true" />
</xslExtensions>


declare it in your xslt:

xmlns:webutil="http://www.sitecore.net/webutil"


then use it (example from a "print page" footer):

<xsl:text>Artiklens placering: </xsl:text><xsl:value-of select="webutil:GetServerUrl()" /><xsl:value-of select="sc:path(.)" />

util:GetString

It might be not obvious but is common practice to use util:GetString(string, default).

A xsl:choose used to display the title of an item can be replaced as follows:


<xsl:choose>
<xsl:when test="sc:fld('menutitle',.)">
<xsl:value-of select="sc:fld('menutitle',.)">
</xsl:when>
<xsl:when test="sc:fld('title',.)">
<xsl:value-of select="sc:fld('title',.)">
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="./@name">
</xsl:otherwise>
</xsl:choose>


simpler call:


<xsl:value-of select="util:GetString(util:GetString(sc:fld('title',.), sc:fld('menutitle',.)),@name)"/>