Sitecore Development Best Practices

Sitecore Best Practice Series:


# Description Rationale
1 Make classes serializable Serialization is used by Application Session and ViewState in .NET; if objects are serializable, the client can easily upgrade to a clustered Sitecore server environment without changing the code.
2 Define separate Navigation Title field Item names may get unnecessarily long for SEO purposes, to make sure this does not affect the display of the item in any menus, use a separate field for a navigation title.
3 Set a default RTE profile If a particular RTE profile is used frequently in item data definition templates, it is easier to set it in configuration instead of having to specify it manually in the Source of the field definition.
4 Do not store content items in /sitecore/system These items are used for configuration settings only.
5 Create content items under /sitecore/content/home Sitecore uses the full item path in URLs for items outside of the /sitecore/content/home by default.
6 Use FieldRenderer control to render field content Field renderer provides ability of editing the field value inside the Page Editor mode.
7 Avoid using XSLT renderings XSLT does is unable to match the speed and flexibility of the C# sublayouts.
8 Specify image dimensions as parameters of the field renderer Sitecore resizes the image on the server end based on certain parameters, which may improve the page load time.
9 Use UserSwitched instead of SecurityDisabler Allows switching to a particular user instead of disabling security layer restrictions completely, which enforces need-based access.
10 Disable ViewState for sublayouts that do not use it Increases sublayout load time and HTML weight.
11 Create abstraction layer for the content items based on item data definition templates It is a good coding practice to use abstraction, Sitecore development is no exception. Abstract each template with an Interface in your solution and implement that interface in a class with custom get and set functionality, getting and setting the field values.
12 Use C# interface implementation to abstract Sitecore item data definition template inheritance C# restricts multiple class implementation, however, allows multi-interface implementation. Matching item data definition template inheritance in content with interface implementation in code will make both easy to maintain.
13 Use Sitecore Rocks Visual Studio plug-in Sitecore Rocks is a great Sitecore extension that makes content management available from Visual Studio, as well as provides additional development tools, making Visual Studio a centralized Sitecore development environment. Sitecore Rocks makes Sitecore developers happy!
14 Stay away from depricated types, properties, and methods Sitecore continuously improves it’s API, deprecating old code and introducing refactored classes and new functionality. It is vital to keep up with the latest changes and avoid using the deprecated code, making client’s Sitecore upgrades in the near future easier to implement without any code changes.
15 Separate custom configuration Separating custom configuration overrides and settings into custom files makes deployments and upgrades much easier to implement.
16 Replace the file extension with the forward slash URLs without extensions are easier to memorize and can be used to represent different file types, such as .htm, .html, .aspx …etc.
17 Iterate through the ChildList instead of the Children property of the parent item in a for loop C# will evaluate the item.Children statement with each loop; prevent this by creating a ChildList and iterate through it instead.
18 Utilize Sitecore utility classes Sitecore has much commonly used functionality built into its utility classes of the Sitecore namespace, use them instead of creating your own.
19 Use item IDs to access items instead of paths Item access by path is slower as it is handled through iterating over each level.
20 Before developing new functionality, check if there is already a module created for that Check available modules at
21 Store frequently changed settings in sitecore items. Avoid unforeseen errors caused by editing configuration files and store frequently changed settings in Sitecore items (Create a configuration item for each website).
22 Use Webforms for Marketers module for forms Avoid implementing custom forms, use Webforms for Marketers module instead as it integrates with the Digital Marketing System and other Sitecore analytics (extend the module if custom implementation is required).
23 Componentize CSS Use sublayout’s parent class as a parent classes in CSS stylesheet for style assignments for the component; this way it will be properly styled no matter where it is placed on the page.
24 Utilize EditFrame control for editing item fields not rendered by the FieldRenderer FieldRenderer Sitecore control can only render simple field types such as an image or a link, however, fields like multilist or TreeListEx will require an EditFrame control to make them editable from the Page Editor.
25 Simplify code and content It is easy to get carried away with creating checkboxes that would trigger certain items to be shown or published, while ignoring the native Hidden field or removing or archiving the item. Make sure you are not reinventing the wheel and keep your code and content simple.
26 Utilize Developer Strip in Content Editor Developer strip provides handy functionality such as serializing database data and restoring it back, making it easy to check in content along with code into the Source Control of choice.
27 Utilize Sublayout Parameters Sublayout Parameters can be used to pass variable values to the .ascx files.
28 Cast field into the API field-type to access its properties Avoid using raw field values, cast the field into a certain type and use the types properties instead.
29 Use Domain Dictionaries Default dictionary is located under /sitecore/system, where editors should not have access to. In addition, multiple Domain Dictionaries can be created to support multi-site instances.