Tuesday, 20 January 2015

The most important rules for Sitecore development.

The most important rules for Sitecore development.
Technology is only as effective as the people that implement it, so making sure you're at the top of your Sitecore development game will be beneficial for your entire organization.

1. Use Page Editor friendly controls

Content author experience is something we talk about often here at nonlinear. Ensuring that your content authors have the capabilities to create and modify content in real time using "what you see is what you get" or WYSIWYG editing is crucial. By incorporating these controls into your development, your content authors will avoid having to delve into the Sitecore content tree to find the matching fields.

2. Don't bind a repeater unless the situation calls for one

The <asp:Repeater> control allows a list of items to be bound to it and causes the specified HTML (and possible code) to be executed for each item. In a basic repeater pattern, there is often a header and footer section that contains HTML that does not repeat. Binding an empty list to a repeater will cause any header and footer HTML that is in the repeater to show up even though no items are repeated. This may be what a user wants, but often that is not the case and by not binding a repeater, you'll be ensuring that none of the HTML in the repeater will show up on a page.

3. Ensure proper null checks before accessing an object

To do this, the first thing you should check, with any variable or method, is to determine if the resulting object is null. As a rule, if an object is not initialized, it will be set to the “null” value. Many methods will also return a “null” value if certain conditions are not met. Trying to use an object which has been set null generally results in a run time exception that will cause your website to crash (sometimes gracefully, sometimes not), so ensuring that you are aware of the characteristics of your variables is paramount to good development.

4. Be cautious about HTML generated in backend code

Generally, .ascx files contain HTML which dictates the physical layout of the page, while the .ascx.cs files contain code that populates the layout. Though the general rule is to make sure not to include any HTML in the backend code, there are situations where this method can solve certain issues. The biggest thing with this law is to be aware of what's being used where to ensure that you have an understanding where the results are coming from, either HTML or backend code.

5. Don't code after return statement

Though this one definitely depends on both the situation and your own preference (some people prefer conditions do have a single, standalone return statement at the end of the method) not coding after the return statement is common. If you are trying to simplify multiple bracketing, this is a good option.

6. Before deploying, check commands to ensure a successful Page Editor user experience:

  • Add a component to a page without a data source
  • Add a component to a page and point to an existing data source item
  • Add a component to a page and create a new datasource item for it to use
  • Remove the component from the page
  • Remove/add child items from the component if it is a container component

7. Ensure that all Sitecore fields that require a datasource are properly set

If you have any fields that point to a list of items in Sitecore (or part of the Sitecore content tree) for which you require population from a datasource, ensure that you have correctly configured the datasource to allow a content item to have "valid" values to choose from when accessing that information.

8. Use the Sitecore debugger to find performance issues

Though its use may depend on the type of contract you have with a client, if the budget and time allow, testing out a variety of scenarios, both positive and negative, will help in delivering a thoroughly tested, and ultimately superior, product.

9. Choose icons that correspond to your content types

This one goes back to creating a positive user experience for the content author. By choosing unique and logical icons or icon groups for related items (news, news folder, news listing etc.) you will give them a visual indicator for what type of page or component they are looking for. Sitecore has a number if built in icons. To select one for a page, simple double click on its associated icon in the content editor.

10. Use default standard values (most of the time)

Using standard values to populate certain fields can be a way to make life easier for your content authors, but make sure to thoroughly consider the choice before deciding that's the way to go. Sometimes there will be cases where the process requires a content author to select a value with a possible required validation rule. In those cases, if instead a standard value has been chosen, the content authors will be less likely to reexamine and fill in the value correctly, since it will already appear to be full (with the standard value which may not be what they wanted in the first place).

11. Provide field-level help for your content authors

For each field of a template in Sitecore, a line of text can be added to give a content author more information about what the field should contain and how it should be used. While this can be a pain for developers to fill in and become redundant once a content author is experienced in content creation, it’s still a good practice to help new content authors, or for fields where the content or use of the field is not intuitive.

12. Include real-world content into testing to make sure everything is working as it should

Depending on budget and the type of contract, including some real-world content into your testing should be standard across all projects. Having an ample amount among your pages will help in analyzing the performance of the site, while also testing pagination and ensuring that specific features like sorting function correctly. Other suggested site content includes: image sizing and language variants to ensure that the layout of the pages remain viable. What other Sitecore laws do you abide by when developing? If you enjoyed this post, make sure to check out these other technical Sitecore articles:

  • Overcoming 2 common Sitecore page editor challenges
  • 3 steps to customize your Sitecore security access ribbon buttons
  • Customizing Sitecore's rich text editor for better usability
  • Sitecore developer resource: Timed publication using publisher restrictions

Wednesday, 17 December 2014

Sitecore 8 New Updates.

Many new components were delivered in the new version of Sitecore, as well as, renaming of existing features and packaging of popular modules used in pre-Sitecore 8 versions.

Renamed Components

  • Page Editor = Experience Editor
  • Marketing Center = Marketing Control Panel
  • Email Campaign Manager = Email Experience Manager

New Components

  • Experience Analytics
  • Experience Profile
  • Experience Optimization
  • List Manager
  • Path Analyzer
  • App Center
  • Executive Dashboard

New Features

  • Versioned Layouts
  • Web API Services (SPEAK components and building applications dependent upon Sitecore data)

Existing Features Packaged With Sitecore 8

​Pipeline Changes

While new pipeline processors have been added to accommodate the new Sitecore 8 features, others have been moved with Content Testing and Experience Editing in mind. Below are the main areas of change with regards to pipeline processing:
  • Social related pipelines come configured out of the box.
  • FXM related hooks
  • Everything Analytics
  • Moving of existing pipelines, such as:
    • SPEAK components
    • Experience Editor
    • Web API request handling (higher up in the httpRequestBegin pipeline)
    • RenderField (immediately after httpRequestBegin)

Content Testing

Outside of Analytics, Sitecore.ContentTesting.config changes dominate the difference in Sitecore 8. Take a look at the config patch file. Content tests need to insert themselves in areas to override existing Sitecore rendering and processing handlers, such as:
  • Insert Renderings
  • RenderLayout
  • GetChromeData
  • Data Aggregation
  • Database Agent (background processing to determine if a test has reached statistical relevancy)
  • Content Testing provider (used by ItemManager)

Sitecore Log Analyzer

Sitecore Log Analyzer is a powerful tool for reading and analyzing Sitecore log files. This tool has option to go through error one by one. It can read large log files. It has option to group by any specific errors, warnings, debug and audit messages which are logged by the Sitecore instance/applications. It has ​​options to monitor performance counters. It gives a dashboard experience of application uptime and downtime.  Sitecore administrators and developers can use this tool to troubleshoot or monitor the health of Sitecore applications.
This tool has feature of filtering logs by string or date time. 
Sitecore Log Analyzer screenshot​:
Error.PNG

Saturday, 8 November 2014

Reading values from an Sitecore Item

Reading values from an Sitecore Item

string fieldValue;
  
//Option 1: Getting the fieldvalue directly
fieldValue = Sitecore.Context.Item["MyField"];

 //Option 2: Getting the field and then reading the value
Sitecore.Data.Fields.Field myField = Sitecore.Context.Item.Fields["MyField"];
if (myField != null)
  fieldValue = myField.Value;

Retrieving Sitecore items

Retrieving Sitecore items

All items are accessed through the Sitecore.Data.Items.Item class

You are mostly going to get an instance of an item through the Sitecore.Data.Database class. This allows you to retrieve items normally by specifying a path or an ID. Like this:

//Get the master database through a Factory
Database masterDb = Sitecore.Configuration.Factory.GetDatabase("master");
   
//Retrieving an item with a path through the database
Sitecore.Data.Items.Item myItem = masterDb.Items["/sitecore/content/home"];
  
//Retrieving an item from an item id

Sitecore.Data.Items.Item mySecondItem = masterDb.Items[newID("{BB07A18A-580D-4105-9A1D-F3072D1A0BE3}")];

Sitecore Tokens

Sitecore Tokens


By default there are the following tokens available in Sitecore:
$name: Is replaced with the name of the created item
•$parentname: Is replaced with the name of the parent to the created item
•$date: Is replaced with the current date
•$time: Is replaced with the current time
•$now: Is replaced with current date and time
•$id: Is replaced with the id of the created item
$parentid: Is replaced with the id of the parent to the created item

Wednesday, 5 November 2014

CONFIGURE VISUAL STUDIO 2012 PROJECT FOR SITECORE (v6.4 to v7.5)

CONFIGURE VISUAL STUDIO 2012 PROJECT FOR SITECORE (v6.4 to v7.5)


Steps to configure VS 2012 for Sitecore  (v6.4 to v7.5)

In Visual Studio 2010, to create a project and solution for a Sitecore installation:

  1. Open VS 2012
  2. Click File >> New >> Project :
  3. In the New Project dialog, select .NET Framework 4.5, 
  4. Select the ASP.NET Empty Web Application project model 
  5. Set Name to the name of the project (ProjectName), 
  6. Set Location to the path to the WebSite folder for the project (C:\inetpub\wwwroot\ProjectName\WebSite) 
  7. Uncheck >> the Create directory for solution checkbox
  8. Click OK.
  9. In Visual Studio, click File >> Close Solution.
  10. Move the Properties folder, the .csproj file, and the .csproj.user file from the subdirectory created by Visual Studio (C:\inetpub\wwwroot\ProjectName\Website\ProjectName) to the WebSite subdirectory (C:\inetpub\wwwroot\ProjectName\Website). 
  11. Delete the subdirectory created by Visual Studio (C:\inetpub\wwwroot\ProjectName\Website\ProjectName).
  12. Open Visual Studio and open the newly created .csproj file.
  13. In Visual Studio, delete the /Web.config/Web.Debug.config and the /Web.config/Web.Release.config file from the project.
  14. In Visual Studio, add references to /bin/Sitecore.Client.dll, /bin/Sitecore.Kernel.dll, and any other dependent assemblies that you use in every project. 
  15. Set the Copy Local property to false for each reference to an assembly in the /bin folder.
  16. In Solution Explorer double-click Properties, set a default Assembly name and a Default namespace, and select the appropriate .NET framework version for your version of Sitecore.
  17. To use the /layouts subdirectory and/or the /xsl subdirectory, Go to Solution Explorer, select the project, and then click the Show All Files button. 
  18. Right-click on each relevant subdirectory and then click Include In Project, 
  19. Right-click each of the individual subdirectories and files in that subdirectory and click Exclude From Project. Remember to clear the Show All Files button afterwards, or debugging from Visual Studio could fail.
  20. After build or while closing project, Visual Studio will prompt you to create a solution for the project. Save it as your choice.
Enjoy.......VS2012 with Sitecore...................