Sitecore.Links.LinkManager and the context

Brian Pedersen's Sitecore and .NET Blog

A new feature in Sitecore 6 is the LinkManager. Previously, in Sitecore 5, in order to get a friendly url (an URL with the .aspx extension) you would write the following:

In Sitecore 6, the GetFriendlyUrl() is deprecated. Instead we are encouraged to use the Sitecore.Links.LinkManager. The same piece of code would look like this:

The LinkManager provides us with a lot of features that the GetFriendlyUrl() did not. But it also introduces some pitfalls. The LinkManager runs in a context that is not necessarily the same as the Item you are getting the link from, nor the context you wish to run in. Let me explain. Imagine you write a Sitecore shell extension that returns the path to an item. The Item is grabbed from the web database:

The path to the item is “/sitecore/content/home”.

Now, lets get the item’s URL:

This returns the item URL for…

View original post 181 more words

Advertisements

Fixing System.InvalidOperationException: field When Trying To Open Rendering Parameters in Sitecore

If you’re getting a nasty error that looks like this

RenderingErrorSmall

when trying to open a rendering that you recently created rendering parameters for, this could fix your problem!

Continue reading

Web Forms For Marketers MVC – Terms of Agreement Custom Field Type

Recently the Web Forms For Marketers Module for Sitecore has released support for MVC.  With that, lets go over how to create a custom type to be used on your MVC form.

First you’ll need to add a new type under the Field Types folder.

FieldTypeLocation

Now in your Visual Studio project, create a new class TermsAgreementField.cs that inherits from CheckBoxField.

Note here that I have made this a required field by making IsRequired always return true.

Continue reading

Sitecore Removing New Line Characters

I was recently using the Multi-Line Text field for displaying hours of operation for a series of locations.  The standard value looked something like this:

HoursBefore

The displayed text would be on the right, and the associated microdata would be on the left.  So it’s all smooth sailing from here.  Split on the new line and put the pieces into place, right?  That’s what I thought until I went to edit this text and the page editor and came upon this:

PageEditorBefore

 

Continue reading