My Writings. My Thoughts.
Using JQuery in custom fields
// February 18th, 2010 // 1 Comment » // Custom field, Sitecore
At the moment I’m creating a custom field for tagging content items. I prototyped my custom field in html using JQuery. But when I wanted to convert this to the actual custom field I ran into a problem. As you might know Sitecore uses the Prototype library for all of it’s javascript. And prototype uses the same dollar sign for all of its functions and variables as JQuery does. But JQuery provides a noConflict function where you can reassign the default $.
But then came the next challenge. I needed to use the noConflict function before all other javascript was called. Luckally I remembered that I have seen it before in other custom fields that are on the Shared Source environment. So I started browsing the source code of Alexey Rusakov’s project (Sitecore Fieldtypes) and I found the InjectScripts class which provides an option to add HTML to the section of the Content Editor. There I just added a reference to my JQuery library and off course calling the .noConflict funtion.
namespace Sitecore.SharedSource.Taxonomy
{
class AddScripts
{
public void Process(PipelineArgs args)
{
if (Sitecore.Context.ClientPage.IsEvent)
return;
HttpContext context = HttpContext.Current;
if (context == null)
return;
Page page = context.Handler as Page;
if (page == null)
return;
Assert.IsNotNull(page.Header, "Content Editor <head> tag is missing runat='value'");
string[] scripts = new[]
{
"/sitecore modules/Shell/Taxonomy/jquery-1.4.1.min.js"
};
foreach (string script in scripts)
{
page.Header.Controls.Add(new LiteralControl("<script type='text/javascript' language='javascript' src='{0}'></script>".FormatWith(script)));
page.Header.Controls.Add(new LiteralControl("<script type=\"text/javascript\">$.noConflict();</script>"));
}
}
}
}
So now I can call my JQuery by using “jQuery” in stead of “$” and the field works.
In my opinion this is just an example of how the Shared Source environment can help you. So if you have created a module, field or any thing else please put it on the Shared Source environment so others can benefit from it.
Restricting FieldEditor to specific template based items
// February 17th, 2010 // No Comments » // Sitecore
In Sitecore 6.2 it is possible to integrate FieldEditors. These are command which enables users edit item settings when they work in the page editor. Personally I think it is a great option when you want editors to only work within the Page Editor, and still let them edit settings.
For the blog module that I created I implemented two FieldEditorCommands which let the user edit the blog and entry settings. When you use the default implementation as described in one of the cookbooks users can always click on the ribbon button regarding if the fields are on the currentitem. When those field don not exist on that item, they just get a empty popup.
I decided to restrict the option only to items which are based on a certain template. You can do this the following way:
You’ll need to override the Execute method in the your class (which overrides from Sitecore.Shell.Applications.WebEdit.Commands.FieldEditorCommand).
Then you isolate the function Context.ClientPage.Start in for instance an if statement.
Example:
if (context.Items[0].TemplateID == new ID(Settings.Default.EntryTemplateID))
{
Context.ClientPage.Start(this, "StartFieldEditor", args);
}
else
{
Context.ClientPage.ClientResponse.Alert("Please select an entry first");
}
If anyone else has a better way to get the same results please let me know.
Blog module update
// November 27th, 2009 // 15 Comments » // Sitecore
This week I released the stable version of the EviBlog module. You can download the module from the Sitecore Shared Source. The module works on all Sitecore solutions based on version 6.2.
The module now includes the following features:
- Inline Editing support
- Windows Live Writer integration
- Pingback
- RSS (using the Sitecore 6.2 Integrated RSS)
- Tagging and tagcloud
- Categories
- Comments (you can disable per setting)
- FieldEditors for blog and entry settings
- Custom webcontrols for integrating your own theme
The Shared Source coordinator Jimmie Overby created two video’s (1, 2) which shows you the most common use of the module. Currently I am writing some documentation about how to use the webcontrols in your own theme. With these webcontrols it’s quite easy to integrate the module within an existing Sitecore installation.
Please do not hesitate to use the Shared Source forum when you have questions about the module.
Continue Reading
New Sitecore 6 blog module released
// November 7th, 2009 // 2 Comments » // Sitecore
In the last couple of months I have been working on a new blog module for Sitecore 6.2. It started as a small module just for my own educational purpose but ended up as one of the largest modules I created. The module is a complete rewritten blog module, based upon the functionality of the old 5.3 version. The new version supports inline editing, fieldeditors, webcontrols for custom themes and Windows Live Writer integration. This release includes two sample blogs. One with a standard theme and one custom theme which shows you how to use the custom webcontrols.
List of features
- Windows Live Writer integration (MetaWeblog API)
- Full frontend (inline) editing
- Webedit ribbon (with fieldeditors)
- CSS based themes
- Custom themes possible (one demo included)
- Custom webcontrols (with inline editing)
- Comments
- Tagging and a tagcloud
- RSS Feeds
At this moment the module in still in betá, and I would like to hear your feedback. You can use the comments or just send me a email (mark at evident.nl). When you encounter problems, found a bug or have any other kind of feedback please let me know and I will try to reply as soon as possible.
You can find the installation package and sources on the Shared Source environment.
Sitecore released version 6.2!
// October 21st, 2009 // No Comments » // Sitecore
Today Sitecore released version 6.2. According to the change log their are several new (cool) features.
- Sitecore client RSS feeds for items in workflows
- Built-in support for syndicating items using the RSS format.
- WebDAV support in the media library
- A new File Drop Area field type has been introduced
- A new Word Field has been introduced!
- Analytics Oracle support
- Improved IIS7 support
- Sitecore’s theme icons are now stored in zip-files.
- Sitecore is now distributed with a number of icons that are having a Windows 7-look instead of an XP-look.
Besides that their are many improvements and fixes.
Go check it out! I’m installing it right now and gonna have a a look.