Friday, December 19, 2008

Adding buttons to inline-editing frame

Today's post is dedicated to Sitecore inline-editor and some customization you can put into it. The question I'm going to address is:
"Is it possible to add custom buttons to inline-editor frame?"
The answer is simple as is: "Yes, it is" :). Wait... don't go away. Read further to find out the solution.

Our challenge is to add a button to inline-editor. Let's do that for Rich Text field.
I put this approach into the steps to outline this process. Let's start:

1) Open Sitecore Client and go to the Core database.
As you know (or maybe you're going to find out right away) Rich Text field has several profiles to give different sets of functionality to logged in users. Let's go to default profile and check its configuration, here is the path in content tree: "/sitecore/system/Settings/Html Editor Profiles/Rich Text Default".

2) The configuration node we're interested in is "WebEdit Buttons". Go ahead and expand it.
Beneath the node you can see all available buttons which are going to show up as soon as you put mouse cursor over the rich text data in Page Editor.



3) Since we're already here let's add our own button to the current set. A button should be created from "/sitecore/templates/System/WebEdit/WebEdit Button" template.



Header field contains the name of the button in inline-editor frame.
Icon field has the icon for the button
Click field is the most important part. It has command message that should be sent when you hit the button.

a) Here is the format of this field for the custom command: "javascript:return Sitecore.WebEdit.editControl($JavascriptParameters, "webedit:mybutton:message")"
Javascript command is required to set you command message that is passed as second parameter for the "editControl" function.
"webedit:mybutton:message" is command message. Don't be concerned about the format of this message. It can have any format you want. For instance: "webedit:mymessage" or "webedit:mybutton:mymessage". It's good when the first part of the message describes an area the message belongs to, e.g. "webedit:".

b) Here is another example to run JavaScript function through the button.
Click field should look like this: javascript:Sitecore.WebEdit.execute("js_function_name", true, "parameter_for_js_function");
This example changes the font size:
javascript:Sitecore.WebEdit.execute("fontsize", true, "20");

NOTE: if you use javascript function, the Header field for the button item should be left empty.

Tooltip field describes itself :).

4) This is the final step. You have to create a command handler that will do action you want.
I'm not going to touch command creation process here. You can find sample in John's article here.
NOTE: webedit command handler class must be inherited from Sitecore.Shell.Applications.WebEdit.Commands.WebEditCommand one.

Friday, July 25, 2008

Migrate from 5.3 to 6.0 (alpha)

Today was my first experience with "alpha" version of Sitecore migration from 5.3 to 6.0.
What I can say, that was not so bad :-). Anyways, I have to say that my site was pretty simple and did not have heavy customization (no custom fields, default devices, no proxies).
I migrated only master database because I had only default security objects in my solution.
I followed all steps from documentation and did not face any problems. Altogether it took about 3 hours to migrate my content and clean up my solution from migration tool. Not bad! Again that was the first time when I saw this tool.
In addition I spent about 2+ hours to adjust my code to spin it in Sitecore 6.0.
The most common issue for my renderings was related to pulling out media url using "sc:fld()" function and media item variable.
I had to substitute "sc:fld()" for "sc:GetMediaUrl()".

I thought I would have to do some modifications to get in-line editing working in V6. I was surprised that old buddy "sc:dot" represented this opportunity.
So, as a result it is not so bad as it sounds at the first glance ;-).
You should try it out!

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.