Thursday, April 17, 2008

Share site resources among several sites

If you have lots of sites with similar structure and presentation layer you can make them use resources of one Sitecore site from web.config file. To do this you can create custom SiteResolver and insert it in <httprequestbegin> pipeline just after the native SiteResolver processor.
Using this approach you should have custom SiteResolver processor and special config file where you can map your sites to the same instance of Sitecore site from web.config file. It shows you how you can set several host names for the same Sitecore site in web.config file.
NOTE: This approach is supposed to have “website” site in your web.config file.
Using this idea you can set not only host names but the whole site configuration for the same Sitecore site. In that case you will be able to share cache and other resources among several sites.
Below are the steps how to apply this approach:
1) Create custom SiteResolver and set add it in web.config file just after the native SiteResolver processor, as shown below:
<httprequestbegin>
………………
<processor type="Sitecore.Pipelines.HttpRequest.SiteResolver, Sitecore.Kernel" />
<processor type="SiteMapper.Pipelines.HttpRequest. SimilarSitesResolver, SiteMapper" />
………………
</httprequestbegin>

2) Create special config file (similar.sites.config) to map your sites with the following structure:
<sites>
<site mode="on" name="www.mysite" hostname="www.mysite.dk" language="da-DK" />
<site mode="on" name="www.mysite" hostname="www.mysite.uk" language="en-GB" />
<site mode="on" name="www.mysite" hostname="www.mysite.com" language="en" />
</sites>

As you can see all three sites have the same “name”. This name determine which site from web.config file should be used when you request any of these sites.
Example of web.config file:
<!-- ***** www.mysite group ***** -->
<site mode="on" name="www.mysite" hostname=" www.mysite.com" language="en" virtualfolder="/" physicalfolder="/" rootpath="/sitecore/content" startitem="/www.mysite/home" database="web" domain="extranet" allowdebug="true" cachehtml="true" htmlcachesize="10MB" enablepreview="true" enablewebedit="true" enabledebugger="true" disableclientdata="false" />
<!-- “website” is compulsory for this solution -->
<site name="website" virtualfolder="/" physicalfolder="/" rootpath="/sitecore/content" startitem="/flugger/home" database="master" domain="extranet" allowdebug="true" cachehtml="true" htmlcachesize="10MB" enablepreview="true" enablewebedit="true" enabledebugger="true" disableclientdata="false" />

NOTE: each Sitecore site in web.config file must have hostName attribute. Otherwise Sitecore will classify this site as a default website and you won’t get required results.

Here is Sitecore package.

Monday, March 31, 2008

Convert unversioned media to versioned

This tool is intended to make a work with media be smoothly. By default Sitecore uploads media as unversioned data. In order to have different media data for different languages we need to upload media as versioned. Otherwise you won't be able to have different data for the same media item. Even if you change unversioned template to versioned.
After installing the package a "Make versioned" button will be available on Media tab.


You can convert media item as well as the whole media folder.

You can download sitecore package from here.

Monday, March 3, 2008

Cross Database TreeList Field

Sometimes we would like to have an opportunity to get data from another database in sitecore field. Since we already have source code of TreeList field on SDN, I decided to adjust it a little bit to have such opportunity.
To allow cross db usage I had to add one parameter to the source query of TreeList field.
It's SourceDatabaseName parameter.
Here is example how to get users from security database in TreeList field.
DataSource=/sitecore/users&SourceDatabaseName=security

Here is the way it looks:


To get rid of broken links in this field I had to MultilistCrossDbField which is intended to validate links correctly in LinkDatabase. So, don't forget to add the line below into /App_Config/FieldTypes.config file:

<configuration>
............
<!-- Custom fields -->
<fieldtype name="tree list cross db" type="Custom.Data.Fields.MultilistCrossDbField,TreeListCrossDB">
</fieldtype>
</configuration>

I added support for "query:" definition into this field. Now you can use either "/sitecore/content" or "query:/sitecore/content/*" as a data source for the field.

Here is Sitecore Package for the field.
Here is source code.

Friday, February 29, 2008

Go To Item tool

Sometimes you have item ID or somebody provides you with pretty long item path and you want to navigate to the item as fast as you can. Of course you can use DBBrowser tool but it's not very convenient switching between several browser windows, isn't it.
So, I created a "Go To Item" tool and I like to share it with Sitecore lovers :).
To get it working you have to install the attached Sitecore package on your Sitecore.
After installation you can see the "Go To Item" button on Developer tab.


After clicking the button you get dialog window where you should input item path/ID. Since /sitecore item is a root of any sitecore trees you can avoid it in item path.


Here is Sitecore package (follow readme instruction during installation).
Here is GoToItem sources.