Following the recent merger between EPiServer and Ektron, many website owners are now considering migrating from Ektron to EPiServer. But in addition to the site owners, web developers who are well-versed in Ektron are also finding that they will need to learn how to translate their expertise into a new platform. We’ve worked with both platforms extensively, so we wanted to share some tips that can help developers that are new to EPiServer understand how to get the most out of the platform. This is the first in a series of blogs in which we'll share tips for EPiServer developers, so please stay tuned as we continue to look at EPiServer development. Here are some basics to get us started:
In Ektron, the only known content reference for a new site is the root content folder which has the identifier of zero. There is no way out of the box to specify a homepage, but having a reference from a settings smart form with a content selector quickly resolves the issue. In EPiServer, there are some references that are almost always available from anywhere in the code from the start which are:
- EPiServer.Core.ContentReference.StartPage (only available within an HTTP context)
Navigation Selected States
Many web sites these days include a visual element in the site navigation to indicate the current or active section of the web site for the visitor. In Ektron, determining the current section is typically done by checking the ID of the current page to a content ID in the site navigation item. In EPiServer, ContentReference identifiers are slightly more complex in that they contain a WorkID for versioning. To account for this, the EPiServer API has a method on a ContentReference of CompareToIgnoreWorkID, which does as it says, compares the content references ignoring the version.
Creating Structured Content (Page Types and Block Types)
My previous article compares how Ektron and EPiServer differ in creating structured content and dynamic pages. For EPiServer, when creating structured content types, knowing what properties are available is very handy, and EPiServer provides many out of the box. Here is a list of built-in types (also note that any block type can be used as a PageData property):
Default Property Values
In Ektron, default values are specified when creating smart forms within the work area. In EPiServer, page types are typically created by classes, so to set the default values, the SetDefaultValues method is available to override for your page type to set the defaults. The following snippet shows how to set a DateTime property to the current date and time:
Utilizing property attributes are a great way to simplify content creation, and EPiServer utilizes many built-in .NET attributes, as well as providing several of its own.
- Display – sets name, sort order, group name (tab) in the UI.
- Required – requires a value before the content can be published.
- Editable(true or false) – makes field read-only in the UI if false is passed.
- UIHint(hint name) – EPiServer.Web.UIHint.LongString makes a string property appear as text area. These hints can also be used for ContentReference properties to open an image selector using EPiServer.Web.UIHint.Image or choose block folder using EPiServer.Web.UIHint.BlockFolder. If there isn't an input type or style that you prefer, the UIHint attribute can also be used with your own custom-developed input types and associated UI.
- CultureSpecific – makes property unique per language.
- Searchable – includes the property in the search index.
- AllowedTypes – used on ContentArea and ContentReference properties to restrict the types of content allowed to be referenced within them.
Developers can also create custom attributes; here are some great resources for doing so:
Using extension methods can quickly speed up coding by simplifying the syntax to operate on data. The following code example provides an extension to quickly get a page type’s content from a given content reference:
Creating global settings like a web site logo, footer text, social media links, and company information is always useful to have and should never be hard coded. In EPiServer, these settings are best stored in a settings block that is assigned to the startpage type. Accessing them then simply becomes:
For developers who are familiar with Ektron content strategies, EPiServer has similar content events, and adding Alf Nilsson’s EPiEventHelper to your web site code will greatly simplify implementing events, as the functions can be stored within the class that makes the page type by implementing specified interfaces such as IPublishedPage.
To determine if content is being edited, the following property can be checked: EPiServer.Editor.PageEditing.PageIsInEditMode.
To get content that has not been published use language overload and pass: LanguageSelector.AutoDetect(true) when calling GetChildren<T>.
To personalize a list of content based on visitor groups, use: EPiServer.Filters.FilterForVisitor.Filter.
New developers will want to utilize both the Visual Studio Extensions, which simplifies creating page types, block types, and templates, and the EPiServer NuGet Feed which helps you keep EPiServer up to date with the latest releases which come every two weeks thanks to their continuous release process.
In addition to these tips, more resources can be found in EPiServer's developers guide, their developer forum, and their blogging community. If you have any questions for us about how to use the methods we've discussed, or if you want to know more about EPiServer development, please contact us to speak to a Solutions Engineer. Do you have any questions about EPiServer development that we can discuss in future blogs in this series? Please share them in the comments below.
Have Questions About This Post?
Website Traffic Woes?
Google search algorithm updates can wreak havoc on your website’s traffic. Don't let your organic rankings tank. Our free SEO health check can help you identify issues that make Google unhappy with your site.
Subscribe to Our Blog
The latest trends in web design, inbound marketing and mobile strategy