February 11 2009
ShowLink Title extension
Just something little that might be of use is an xslExtension to display Titles and Titles as tooltips.
Created a ShowTitle.cs class that gets passed an Item’s ID as a string then fetches title fields; Navigation Title, or Page Title (if Navigation Title is blank), or finally the Name of the Item if both Navigation and Page Title fields are blank.
public static string DisplayTitleLink(string PageID)
{
string PageTitle = "";
string NavigationTitle = "";
Item page = Database.GetDatabase("master").GetItem(PageID);
PageTitle = page.Fields["Page Title"].ToString();
NavigationTitle = page.Fields["Navigation Title"].ToString();
if (NavigationTitle != "")
return NavigationTitle + ". ";
else if (PageTitle != "")
return PageTitle + ". ";
else
return page.Name;
}
Included this extension in the web.config file:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<xslExtensions>
<extension mode="on" type="Proj.Common.ShowTitle, Proj.Common" namespace="http://www.sitecore.net/km" singleInstance="true"/>
</xslExtensions>
</sitecore>
</configuration>
In the XSL stylesheet:
<sc:link text="{km:DisplayTitle($itemID)}" title="{km:DisplayTitleLink($itemID)}"></sc:link>
So now when my link displays it includes a “. ” after as the tooltip - this is handy for renderings such as Left Navigation or Breadcrumb for example that require proper tooltips, rather than have an extra template in the XSL stylesheet to check for Page titles.
5pm
February 09 2009
Quick post
Hi all, just wanted to post a short note to say that my blog is still alive! I am hoping to post a lot more stuff for 2009 on Sitecore as I will be working on (hopefully) more projects this year. Thanks :)
11am
October 06 2008
Flash integration
Working on my first Sitecore 6 project, I was able to have some fun with flash integration. The flash file was already provided for us from a third party, the XML feed was provided for us also, however we had to generate this dynamically with particular content in Sitecore using the format that was given to us.
With the help from my colleague Peter, we first created a blank template “XML Feed” that had no fields. Then created a layout with a single placeholder “xml” and on page load added the following:
Response.ContentType = "text/xml";
The template and the layout were both created outside of the site we were working on so they can be used globally from our CommonClient solution we also created.
In the content tree, there is a folder that holds the feeds, each feed is based on the XML Feed template and assigned the XML Feed layout. For this example, the rendering “PlacesMapFeed” is assigned to the xml placeholder to the XML Feed layout. This rendering will be gathering items under its parent “Places to Visit” that are a number of regions in New Zealand.

XML feed:
<regions>
..
<region id="6">
<title url="http://localhost/regions/lowerNorthIsland.aspx>
<links>
<link>
<title url="http://localhost/regions/oldStPauls.aspx>
<linkURL>http://localhost/regions/oldStPauls.aspx</linkURL>
</link>
..
</links>
</region>
<region id="7">
..
</region>
</regions>
Items:
The items below, each <region></region> has a <link></link> or a certain place under that region:

In the flash file, each region has their own region id number, to ensure the correct region matches their region id number, the configuration item “PlacesMapRegions” has the names of the regions in order of their region number so they match (Lower North Island region should be id=6:

Rendering:
Variables:
<!-- variables -->
<xsl:variable name="root" select="$sc_item/ancestor-or-self::item[../../@key='sitecore']"/>
<xsl:variable name="home" select="$root/item[@key='home']"/>
<xsl:variable name="configItems" select="$root/item[@key='settings']/item[@key='configuration items']"/>
<xsl:variable name="regionIndex" select="sc:fld('Text',$configItems/item[@key='placesmapregions'])" />
<xsl:variable name="placesToVisit" select="$home/item[@key='placestovisit']"/>
Main:
<xsl:template match="*" mode="main">
<regions>
<xsl:for-each select="sc:SplitValue($regionIndex)">
<region id="{position()-1}">
<xsl:call-template name="getRegionItem">
<xsl:with-param name="regionName" select="."></xsl:with-param>
</xsl:call-template>
</region>
</xsl:for-each>
</regions>
</xsl:template>
getRegionItem:
<xsl:template name="getRegionItem">
<xsl:param name="regionName"/>
<xsl:variable name="regionItem" select="$placesToVisit/item[@key=sc:ToLower($regionName)]"/>
<title url="{sc:path($regionItem)}">
<xsl:call-template name="text">
<xsl:with-param name="itm" select="sc:item($regionItem/@id,.)"></xsl:with-param>
</xsl:call-template>
</title>
<links>
<xsl:call-template name="displayLinks">
<xsl:with-param name="regionItem" select="$regionItem"></xsl:with-param>
</xsl:call-template>
</links>
</xsl:template>
displayLinks:
<xsl:template name="displayLinks">
<xsl:param name="regionItem"/>
<xsl:variable name="placeToVisitItem" select="$regionItem/item[@template='place to visit']"/>
<xsl:for-each select="$placeToVisitItem">
<xsl:if test=".!=''">
<link>
<title url="{sc:path($placeToVisitItem)}">
<xsl:call-template name="text">
<xsl:with-param name="itm" select="."></xsl:with-param>
</xsl:call-template>
</title>
<linkURL>
<xsl:value-of select="sc:path(.)"/>
</linkURL>
</link>
</xsl:if>
</xsl:for-each>
</xsl:template>
Text:
<xsl:template name="text">
<xsl:param name="itm" select="." />
<xsl:choose>
<xsl:when test="sc:fld('Navigation Title',$itm)!=''">
<xsl:value-of select="sc:fld('Navigation Title',$itm)" />
</xsl:when>
<xsl:when test="sc:fld('Page Title',$itm)!=''">
<xsl:value-of select="sc:fld('Page Title',$itm)" />
</xsl:when>
<xsl:when test="sc:fld('__Display Name',$itm)!=''">
<xsl:value-of select="sc:fld('__Display Name',$itm)" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@name" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
The flash file shows the region and its places:

Finally, in our General Layout we reference the flash feed:
<script type="text/javascript">
// map
var flashVars2 = {
configXML: "/Feeds/PlacesMapFeed.aspx" ,
debug:"true"
};
swfobject.embedSWF("/destinations/flash/large_map.swf", "flash_map", "478", "670", "9.0.0", "/destinations/flash/expressInstall.swf" , flashVars2);
</script>
That was it! Was fun and worked nicely :)
2pm
September 25 2008
Futureintech: First school visit

I am happy to also be part of Futureintech, a chance for a representative like myself for Datacom in an industry such as ICT, to speak with prospective students - ages range from Primary school (ages 5-13) to Secondary school (13-18) to encourage and inspire them in a career in technology.
My very first school visit was Heretaunga College and I spoke to a small IT class which then got broken down into three more interested students. It was a great experience sharing my pathway to my current career and talking about what I went through to get here.
I was very impressed with the three students who were aged from about 15 to 17 and was suprised at how much they knew already. They talked about using PHP, XML, SQL, some web tools such as the developer toolbar in Firefox and showed me a school website project that they were working on. Their teacher was very supportive and pleased with the work they had done and particularly, really proud of how much they had achieved so far.
Futureintech is a great program to reach out to students and bridge the gap between industry and tertiary foundations and encourage students to start thinking about their careers. Hopefully such school visits as these can influence students to seriously think about their future in technology - hopefully developing/coding software like myself!
5pm
August 20 2008
Sitecore Webforms for Marketers Module
Webforms for Marketers is Sitecore’s new forms module for Sitecore Version 6. It is completely embedded in the page editor (in context) and has great functionality.
I am yet to have a go at Sitecore Version 6 and the Webforms module but doesn’t look too bad so far!
3pm
Solution! IIS Doubles image size when using original file extension
Thanks to the support guys at Sitecore we were able to solve this problem with images accessed from the file system.
The solution was a change to the Web.Config file. The ISAPI extension mapping settings have remained unchanged, however for Windows 2003 Server there is an extra step which is adding the StaticFileHandler HttpHandler to the Web.Config file.
For Windows XP:
Web.config:
<processor type="Sitecore.Pipelines.HttpRequest.FilterUrlExtensions, Sitecore.Kernel">
<param desc="Allowed extensions (comma separated)">aspx</param>
<param desc="Blocked extensions (comma separated)">*</param>
<param desc="Blocked extensions that stream files (comma separated)">
</param>
<param desc="Blocked extensions that do not stream files (comma separated)">*</param>
</processor>
For Windows 2003 Server:
Web.config:
<processor type="Sitecore.Pipelines.HttpRequest.FilterUrlExtensions, Sitecore.Kernel">
<param desc="Allowed extensions (comma separated)">aspx</param>
<param desc="Blocked extensions (comma separated)">*</param>
<param desc="Blocked extensions that stream files (comma separated)">
</param>
<param desc="Blocked extensions that do not stream files (comma separated)">*</param>
</processor>
Extra step for Windows 2003 Server - add StaticFileHandler HttpHandler:
<httpHandlers>
<add verb="GET,HEAD" path="*.jpg,*.txt,*.gif" type="System.Web.StaticFileHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
..
</httpHandlers>
In the path attribute we have included ALL file extensions we wish to store in Sitecore.
And now the document size of pages have decreased by almost half :)
2pm
August 13 2008
Setting up a Common solution: FieldTypeExtensions
We have set up a Common solution project to provide a lot of common methods and classes that our projects will use. As we have multiple Sitecore websites we are working on, we have created this solution to allow us to configure multiple sites as well as allowing us to create multiple instances of a site.
Our Common solution has a project: FieldTypeExtensions. Within this are several classes used for our custom fields we have created. In order to create another instance of the same site (literally copying and pasting a website in Sitecore), we must allow for certain fields to be referencing its own site. For example, if one of your fields is a multilist with a source pointing to a folder in the content tree and you copy an instance of the website, you want the datasource of this multilist to now have the source of the new instance you have created.

Create the custom field
Under system > Field types, create a new field type, for this example, “custom tree list”.

Create the class in the Common solution
Under our FieldTypeExtensions project we have several custom fields.

In this class, we are replacing the “{root}” part of the source [DataSource={root}/Common/Categories&IncludeTemplatesForSelection=Category], with the path to the current site.
public new string Source
{
get { return base.Source; }
set
{
if (value.Contains("{root}"))
{
base.Source = value.Replace(
"{root}",
Configuration.GetStartPath(Sitecore.Context.ContentDatabase.Items[this.ItemID]));
}
else
{
base.Source = value;
}
}
}
So now when you copy an instance of the site, all fields that have similar data sources may be dynamically updated. The same can be done for custom internal link, link, lookup, tree fields.
10am
July 31 2008
IIS doubles image size when using original file extension
We have configured IIS to use original file extensions (.jpg, .gif, etc) - we have configured ISAPI application mappings so that our Google box can search images from the Media Library (so it doesn’t use the .ashx file extension).
Images that are being accessed from the file system directly (for example, www.site.com/images/img.gif) have appeared to have a size double than its original size. This is a problem for us as pages are required to be kept to a certain size.
The file opened in a browser using the original media extension are being served twice.
Along with mapping the file extensions, a change had to be made to the FilterUrlExtensions section Web.Config:
<processor type="Sitecore.Pipelines.HttpRequest.FilterUrlExtensions, Sitecore.Kernel">
<param desc="Allowed extensions (comma separated)">aspx</param>
<param desc="Blocked extensions (comma separated)">*</param>
<param desc="Blocked extensions that stream files (comma separated)">doc,dot,rtf,docx,pdf,txt,xls,xlsx,csv,mpp,msg,xml,jpg,jpeg,png,gif,bmp,tif,.. etc</param>
<param desc="Blocked extensions that do not stream files (comma separated)">*</param>
</processor>
This change above was so that we can actually view the images that are being accessed from the file system directly, this does not affect images that are accessed from the Media Library - these are fine.
However, this is causing the images to double in size - which we don’t want, but we still require the mapping.
We modified the FileUrlExtensions section in Web.Config yet again to the following:
<processor type="Sitecore.Pipelines.HttpRequest.FilterUrlExtensions, Sitecore.Kernel">
<param desc="Allowed extensions (comma separated)">aspx</param>
<param desc="Blocked extensions (comma separated)">*</param>
<param desc="Blocked extensions that stream files (comma separated)">*</param>
<param desc="Blocked extensions that do not stream files (comma separated)">*</param>
</processor>
We replaced the extensions with a *. In Windows XP - this works fine, the images are being kept at their original size AND we can view the image in the first place.
In Windows Server 2003 however, this unfortunately does not allow us to view the images. But by having the list of file extensions in the <param desc=”Blocked extensions that stream files (comma separated)”></param> section seemed to fix it.
We are hoping someone may have a possible solution for this! It would be very appreciated.
3pm