Thursday, 28 August 2014

Sitecore Modal Pop-ups are not working in Chrome

Recently I’ve faced strange issue while working with Sitecore.NET 7.0. (rev. 130810) in Chrome browser.  I was trying to access presentation details of Sitecore item and layout details pop-up was not coming properly. I’ve checked Chrome console to verify if there is any JavaScript error. I’ve seen below error in Chrome console:
Uncaught ReferenceError: showModalDialog is not defined
This issue is not occurring in Sitecore 7.2 version. After troubleshooting I’ve found that this issue was occurring in Chrome version 37.x. Chrome 37 disables support for showModalDialog by default thus window.showModalDialog() won’t work anymore in Chrome 37 onwards.  For more information refer to the chromium blog. However, Google has added a temporary Group Policy setting EnableDeprecatedWebPlatformFeatures to re-enable deprecated web platform features for a limited time. In May 2015, this setting will be removed and showModalDialog will be completely removed from Chrome. Below section describes the steps to enable EnableDeprecatedWebPlatformFeatures policy setting to Chrome, which administrators can then configure via Windows Group Policy:
  1. Download ADM policy templates for Windows from here.
  2.  Unzip downloaded zip file and navigate to Start > Run: gpedit.msc
  3. Navigate to Local Computer Policy > Computer Configuration > Administrative Templates.
  4. Right-click Administrative Templates and select Add/Remove Templates.
  5. Add the downloaded chrome.adm template of Windows via the dialog for the specific language. In my case; I’ve selected adm templates for en-US locale.
  6. Once added, a Google Chrome folder will appear under 'Classic Administrative Templates' if it's not there already.
  7. Select EnableDeprecatedWebPlatformFeatures setting in right column and edit it.
  8. Edit EnableDeprecatedWebPlatformFeatures as shown in below image.
  9. Restart chrome browser and type chrome://policy/  in address bar and you will see that setting is enabled now. 
  10. Above procedure will create/update windows registry value. 
This setting doesn't need to be configured manually! Starting with Chrome 28, policies are loaded directly from the Group Policy API on Windows. Policies manually written to the registry will be ignored. Starting with Chromium 35, policies are read directly from the registry if the workstation is joined to an Active Directory domain; otherwise the policies are read from Group Policy Objects (GPO).
Order of Precedence for Chrome Policies:
Related articles:

1.) SDN Forum : showModalDialog disabled by default in Chrome 37
2.) Sitecore Knowledge Base Article

Comments and suggestions are most welcome. Happy coding!

Saturday, 9 August 2014

Sitecore Page Editor Mode renders raw/json value as content

Leave a Comment
Recently I have faced one strange issue while working with Sitecore Page Editor Mode. Sitecore Page Editor Mode was rendering some raw json value as content. In this post I am going to narrate my findings while doing the troubleshooting. Please note that I am working with Sitecore7.0 with MVC enabled.
  • John West has already written great blog related to this issue. Please refer to John’s blog which describes resolutions to issues that can cause the Page Editor in the Sitecore to render a jumble of JSON as part of the content of a page. 
  • Ensure that webedit.css file is getting loaded and accessible. You’ll find below setting in web.config file:
    <setting name="WebEdit.ContentEditorStylesheet" value="/webedit.css"/>
    Value attribute specifies the location where webedit.css is located. By default the webedit.css file is located at the root of website. In my case, webedit.css was getting loaded perfectly.
    If webedit.css is not getting loaded into DOM then add a reference to the webedit.css in <head> of layout to resolve the problem.
  • Ensure that Sitecore.MvcExperienceEditor.config file is enabled if you are working with Sitecore MVC. You can find this file at \App_Config\Include folder. Sitecore.MvcExperienceEditor.config file is responsible to render all required javascript/css files in page editor mode.
  • Verify that you are not getting any jQuery conflict related errors. If yes, then override $ function by calling "jQuery.noConflict()".
    <script type="text/javascript" src="jquery-1.8.3.js"></script>
    <script type="text/javascript">
    var jq = jQuery.noConflict(true);
    $jq(document).ready(function() {
     // Your jQuery related code go here. Use $jq for all calls to jQuery.
  • Ensure that Layout HTML is not causing any issue in page editor mode. Following code was written in BaseLayout.cshtml file to render IE version specific conditional css classes on body tag:
    <!--[if lt IE 8]>      <body class="lt-ie9 lt-ie8"> <![endif]-->
    <!--[if IE 8]>         <body class="lt-ie9"> <![endif]-->
    <!--[if gt IE 8]><!-->
    Bingo! It was the culprit who was causing the main issue. I’ve removed code of loading conditional css classes on body tag and I was no longer getting jumbled json in Sitecore Page Editor Mode.
Drop a comment below if you are aware of any additional solution for resolving this issue. Comments and suggestions are most welcome. Happy coding!

Sunday, 3 August 2014

Sitecore Fast Query v/s Sitecore Query: Interesting Observation

Leave a Comment
I’ve been working with Sitecore Fast Query and Sitecore Query for a long time. Sitecore Fast Query is translated to SQL queries that be executed by the database engine. Fast Query is more efficient in terms of execution time and performance as compared to Sitecore Query. Few days ago I’ve noticed that Sitecore fast query doesn’t return hierarchical result set as compared to Sitecore content tree structure. In other words, Sitecore Fast Query retrieves a plain list of the Sitecore items regardless of the content tree hierarchy.
  • Sitecore Content Tree Structure:  Below image is part of Sitecore content tree. I’ve to find out all descendants of AccordionBottom item (item id = {2FCB17C4-8EB2-427E-97FE-12A0BECE4044}) that are based on the template with the specified Id.
  • Fast Query: Below Fast Query returns result set in jumbled order.
    fast://*[@@id = '{2FCB17C4-8EB2-427E-97FE-12A0BECE4044}']//*[@@TemplateId = '{39ACE8CB-4EE3-4989-9B73-5CAFEC21B70C}']
  • Sitecore Query: Below Sitecore Query returns result set in hierarchical order as per content tree structure.
    //*[@@id = '{2FCB17C4-8EB2-427E-97FE-12A0BECE4044}']//*[@@TemplateId = '{39ACE8CB-4EE3-4989-9B73-5CAFEC21B70C}']
Use Sitecore Query instead of Fast Query if your code logic depends on Sitecore content tree structure and you have to render the items in the same order as they are appearing in Sitecore Content tree. 
Comments and suggestions are most welcome. Happy coding! 

Error realted to Item Id while working with Glass Mapper in Sitecore page editor mode

Leave a Comment
Today I was working on Sitecore Glass Mapping framework for my Sitecore MVC project. I’ve installed Glass Mapper from nuget and configured it for Sitecore MVC project. For more information on the Glass.Sitecore.Mapper visit the official website. Thanks Mike and Tom for this great framework. Below are the few details about my development environment:
  • MVC Version:  4Sitecore Version:  7.0
  • Glass.Mapper version:
  • Glass.Mapper.Sc version:
  • Glass.Mapper.Sc.Mvc version:
  • Glass.Mapper.Sc.Razor version:
I am using SimpleInjector IOC container to create objects that are used by Glass.Mapper rather than default Castle Windsor or default inbuilt Glass.Mapper method. Using other IOC container with Glass.Mapper is very easy and I got my webpage up and running in Sitecore normal mode easily. However I got below error while working in Sitecore Page Editor Mode.
You can not save a class that does not contain a property that represents the item ID. Ensure that at least one property has been marked to contain the Sitecore ID. Type: SitecoreRamblings.Models.NewsModel
   at Glass.Mapper.Sc.Configuration.SitecoreTypeConfiguration.ResolveItem(Object target, Database database)
   at Glass.Mapper.Sc.GlassHtml.MakeEditable[T](Expression`1 field, Expression`1 standardOutput, T model, Object parameters, Context context, Database database, TextWriter writer)
Below is the implementation of Model class:
using Glass.Mapper.Sc.Configuration.Attributes;
using SitecoreRamblings.Service.Interface;

namespace SitecoreRamblings.Models
    [SitecoreType(AutoMap = true)]
    public class NewsModel
        private readonly INewsService _service;       
        public virtual string Title { get; set; }
        public virtual string Body { get; set; }
        public virtual string Abstract { get; set; }

        public NewsModel(INewsService service)
            _service = service;
After investigation; I’ve realized that I forgot [my stupidity on peak :( ] to add an additional property in NewsModel class to represent the Sitecore ID. I’ve added below property in NewsModel class:
public virtual Guid Id { get; set; }
Sitecore ID is required to allow Glass.Mapper to link your model to the actual Sitecore item in Page Edit mMode. After building solution, I was no longer getting error in Page Editor Mode.
Comments and suggestions are most welcome. Happy coding!