How to change the sc:link tag to render a specific type when using page editor

Update: this was reported as a bug, and has been fixed in version 6.6 rev 3 onwards.

The sc:link field provided by Sitecore in conjunction with the ‘General Link’ field type is a really flexible combination. When setting a field type in a template as ‘General Link’, it gives a variety of options for links that can be inserted in that field:

Different types of link insert options

When editing an item through the content editor, clicking on each different type of link will open a different window, with the appropriate fields to enter information:

External Link Window
Internal Link Window
Media Link Window

However, there is no option to set the link type in the control when placing it in the sublayout – so users that edit the item in page editor always see the first type (which is ‘internal’) or if the item was already edited via the content editor, they will see the type of link that was set by the user when they created/updated it.

Edit Link Option when using Page Editor

I thought this was odd behavior and researched a little bit to find that the foundation of the field was still the xsl link field – which did have a linktype. A little more research led me to find that you can set it to a certain type for the users that use page editor, by putting in the definition in the raw values option.

So, to do this, you will need to create a standard values for the template. Once you do that, go to View and check ‘Raw Values’. Once checked, go into the field in your template, and put the following text:

<link linktype="external" url="" anchor="" target="" />

Now, when you go into page editor, and you click on ‘edit link’ icon, it will open the type that you set. The different link types are:

  • internal
  • external
  • mailto
  • anchor
  • javascript

Each of these have different attributes as well – the example above shows the values for when the linktype is ‘external’, which has options for url, anchor and target.

Here are the attributes available for all the types:

<link text="" linktype="internal" url="" anchor="" querystring="" title="" class="" target="" id="[sitecore item id]" />
<link text="" linktype="media" url="" title="" class="" target="" id="[media item id]"/>
<link text="" linktype="external" url="" anchor="" title="" class="" target="" />
<link text="" linktype="anchor" url="" anchor="" title="" class="" /> 
<link text="" linktype="mailto" url="" anchor="" title="" class="" />
<link text="" linktype="javascript" url="" anchor="" title="" class="" />

This still only gives you the option in the page editor to have only one type of link. This is OK for most situations, I would imagine, and the types can always be changed in the content editor. If you know of a way to achieve this in the page editor using the command buttons, drop me a note!

An edited version of this post also appears on 1000 lines of code


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s