Link Directly to a Sitecore Item in a Custom Editor

Sitecore’s flexibility as a platform allows for some interesting customizations, including adding to the Sitecore application itself. A nice extension is to create a custom editor to be used in the CMS on content items. Creating a custom editor is a fairly straightforward task, but making it behave like the built-in Sitecore editors is a bit trickier. This post will cover a quick tip to allow you to link to other Sitecore items within your custom editor.

In the past I had written a custom editor for Sitecore to query for a collection of specific items and make a table with various properties of them. In this editor I wanted to create a link on each to go to that item in the tree, similar to clicking the template of an item and going directly to that template. I was never able to get this to work so the hack was to link directly to the content editor page in the shell and pass it various query string parameters. This worked but would open up the new item in a new application instance.

Fortunately, John West of Sitecore USA recently provided some working JavaScript to get this working the correct way. The resulting JavaScript from the SDN forum question is pretty simple. First include these JS files:

<script src="/sitecore/shell/controls/InternetExplorer.js" type="text/javascript"></script>
<script src="/sitecore/shell/controls/Sitecore.js" type="text/javascript"></script>

Then put the following code on a click event:

scForm.getParentForm().postRequest('','','','item:load(id={GUID OF ITEM HERE})');

To see it in use, here’s a hard-coded inline example. (Don’t forget, the return false in a JavaScript click event is bad.)

<a onclick="scForm.getParentForm().postRequest('','','','item:load(id={GUID OF ITEM HERE})'); return false;" href="#">Go to item</a>

The above approach uses the built-in Sitecore JavaScript objects and functions. There’s also the older approach that I’ve used before, but its a bit of a hack since it links directly to the content editor of the shell with some specific parameters:

link.NavigateUrl = string.Format("/sitecore/shell/sitecore/content/Applications/Content Editor.aspx?id={0}&la={1}&fo={0}", itemId, itemLanguage);

Mark Ursino

Mark is Sr. Director, CMS Practice Lead at Rightpoint and a Sitecore Technology MVP.


2 thoughts on “Link Directly to a Sitecore Item in a Custom Editor

  1. Hello, I’m hoping I can still get a response. I tried using this a few weeks ago, but wasn’t able to get it quite working since I couldn’t find documentation on the format. Today, I realized that the internetexplorer.js file has been eliminating text selection and context menus on my site when opened in IE.
    My question(s) is: what is the purpose of internetexplorer.js and why would it do this? I’m not savvy enough to interpret the code.

  2. Hi there,

    I am trying to get this working in a sitecore 6.6 instance, and not having much luck.

    I am using the javascript events as you mentioned, but with o joy

    Go to item

    no errors are being reported

    any help would be appreciated

Leave a Reply

Your email address will not be published. Required fields are marked *