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:

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

Then put the following code on a click event:

[javascript]
scForm.getParentForm().postRequest(”,”,”,’item:load(id={GUID OF ITEM HERE})’);
[/javascript]

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.)

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

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:

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

 

Mark Ursino

Mark is Sr. Director at Rightpoint and a Sitecore 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.
    Thanks.

  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 *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.