Monthly Archives: April 2017

Sitecore Training

Sitecore Training Is Always Valuable

When I first started down the path of doing Sitecore development back in 2008, I was told by the company that I worked for at the time that they had a new CMS system they were going to be using to manage all the customer websites. The company was in the restaurant advertising business, and when they got new a new restaurant we would take the website they had currently, and add them into Sitecore to be managed. Back at that time, CMS systems were just gaining some ground in popularity, and .NET web development was a hot topic. I had been doing some work before with ASP but not a ton of .NET web development much less with enterprise level CMS systems. I was at a Junior level in my development efforts in .NET with lots of knowledge, but not a lot of practical uses of said knowledge in the form of implementations. With that being said, I knew that I had a lot of work ahead of me to learn .NET Web Development, and then learn Sitecore intimately from every angle in order for me to be able to deliver solid solutions. At that time in 2008, the version that had everyone excited was version 6.0. Sitecore, in my opinion, has always been good at providing documentation. However, with that being said, I still had to rely mostly upon Google searches to find most of what I needed to help me out in any way shape or form. It was at this time that John West and his blog posts generally saved the day for most of us that come from that era of Sitecore development, and the reason why he is a lifetime Sitecore MVP. He literally paved the way for us current MVP’s to share our knowledge as back then we were just looking for nuggets anywhere we could get them. From all of us in the community, thank you John West!

Now, back on topic, my company saw that this was a tall order for me to take on, and decided to send me to Sitecore certification training in San Francisco, CA. This turned out to be the best move they could make and money well spent to get me up to speed VERY quickly. I flew out to San Francisco, and for a week learned the nuts and bolts about how to develop a website into the Sitecore CMS system. To be honest, it was a lot to take in and being new to .NET development, some of it was over my head, and I struggled to gain the deep understanding that I very much desired. Luckily, all my documentation I read through before the course and the Google searches paid off because I was more so gaining the validity to what I had been doing on my own versus learning brand new concepts. Days were filled with training and examples, and nights were filled with soaking up what I learned that day and studying for the exam at the end of the course. At the end of the week, I flew back home as a Sitecore Certified Developer.

Armed with my knowledge, certification, and newfound passion for Sitecore, I set out to start building websites. I was able to build my first website in 6.0 that had around 20 micro-sites within it that we were able to manage easily in a very short period of time!

Fast-forward 8+ years later, my previous employer, had an instructor fly out, and provide a group training in SItecore 8.1+ . First, we started out with training on how Content Editors use the system from Content Editor as well as heavy use of the Experience Editor, and all it’s functionality and tools to edit content. Then for the rest of the week, we took a deep dive into how to develop websites into the Sitecore CMS using the latest and greatest tools utilizing best practices for Sitecore development. Having been through Sitecore Certification Training in the past, I was sure that I would not see much new that I didn’t know. To my disbelief, I was blown away at all that I learned that I didn’t know about, in addition to using tools that would help my team’s productivity overall. For instance, in the course, we made extensive use of SIM (Sitecore Instance Manager) and Sitecore Rocks for our development. I have used Sitecore Rocks before, here and there for certain tasks, but not strictly for development forcing me to have to get used to use the tool. It was great see just how easy things were to get what I wanted accomplished without ever leaving Visual Studio! Now, I am using Sitecore Rocks more than ever to help me with my day-to-day Sitecore tasks.

The moral of this story is that Sitecore training is ALWAYS valuable for partners as well as clients! Make no mistake about it, you are only as effective as what your level of knowledge is when it comes to Sitecore. Once you get the training you need in your role, you will be more confident, productive, and ultimately happy working inside the Sitecore CMS. Happy coding!

jQuery JavaScript Language Selector for Sitecore

So I had the need to create a quick language selector, and was surprised that there were not simple JavaScript solutions hanging out with every developers best friend “Google”. So I decided to put out a quick blog post to help out the community with my simplistic JavaScript solution that can be put in your toolbox as reusable code for use with any version of Sitecore.

Below is my HTML:

<li class="SS-LanguageToggle">
     <a id="langSelectEn" href="#">EN</a>
     <a id="langSelectFr" href="#">FR</a>
</li>

First, what I want to happen is when someone clicks the appropriate language, in this case either English or French, I want the language selector to change the site context to the appropriate language not only for that page but for every page thereafter until they either change it back to the other language or clear cookies in the browser (more on that in a bit).

Next, I want to set the class of the selector to the class that will make that selector active. In other words, I want to bold out the selector “EN” or “FR” so that you know it is the active language for the site.

Below is my jQuery snippet in my Main.js file:

/*======================================================== */
/* Switch Language Functionality - Start */
/*======================================================== */
$(function () {
    var currentUrl = window.location.href.toLowerCase();
 
    if (currentUrl.indexOf("en/") > -1 ||
        currentUrl.indexOf("sc_lang=en") > -1) {
        $('a#langSelectEn').addClass("Active");
        $('a#langSelectFr').removeClass("Active");
    }
 
    if (currentUrl.indexOf("fr-ca/") > -1 ||
        currentUrl.indexOf("sc_lang=fr-ca") > -1) {
        $('a#langSelectFr').addClass("Active");
        $('a#langSelectEn').removeClass("Active");
    }
 
    $('a#langSelectEn').on('click', function (e) {
 
        if (currentUrl.indexOf("en/") > -1 ||
            currentUrl.indexOf("sc_lang=en") > -1) {
            currentUrl = currentUrl.replace("en/", "").replace("#", "").replace("?sc_lang=en", "");
        }
        else if (currentUrl.indexOf("fr-ca/") > -1 ||
            currentUrl.indexOf("sc_lang=fr-ca") > -1) {
            currentUrl = currentUrl.replace("fr-ca/", "").replace("#", "").replace("?sc_lang=fr-ca", "");
        }
 
        var switchedUrl = currentUrl + '?sc_lang=en';
        window.open(switchedUrl, '_self');
    });
 
    $('a#langSelectFr').on('click', function (e) {
 
        if (currentUrl.indexOf("en/") > -1 ||
            currentUrl.indexOf("sc_lang=en") > -1) {
            currentUrl = currentUrl.replace("en/", "").replace("#", "").replace("?sc_lang=en", "");
        }
        else if (currentUrl.indexOf("fr-ca/") > -1 ||
            currentUrl.indexOf("sc_lang=fr-ca") > -1) {
            currentUrl = currentUrl.replace("fr-ca/", "").replace("#", "").replace("?sc_lang=fr-ca", "");
        }
 
        var switchedUrl = currentUrl + '?sc_lang=fr-ca';
        window.open(switchedUrl, '_self');
    });
});
/*======================================================== */
/* Switch Language Fuctionality - End */
/*======================================================== */

You will see that in this post, I am mostly using the URL to get/set what I need for the language selector. One other thing I should mention to you is for this example, you will want to have “languageEmbedding” turned on to always. This will give you the “languageIdentifier/” just after your domain name in the URL throughout your site. In this example, it is “en/” or “fr-ca/” as you will see in the JavaScript code above where I am looking that languageEmbedding in the URL.

LinkManager settings that are transformed to Sitecore.config:

<linkManager defaultProvider="sitecore">
    <providers>
      <clear />
      <add name="sitecore" type="Sitecore.Links.LinkProvider, Sitecore.Kernel"
            addAspxExtension="false"
            alwaysIncludeServerUrl="false"
            encodeNames="true"
            languageEmbedding="always"
            languageLocation="filePath"
            lowercaseUrls="true"
            shortenUrls="true"
            useDisplayName="false"
            xdt:Transform="Replace"
            xdt:Locator="Match(name)"/>
    </providers>
  </linkManager>

To set the language for the site, for example, English, you just need to add “en/” after the top-level domain OR add ?sc_lang=en to the end of the URL. Once that is done, the site context is changed for in your browser even if you close it and come back to the site later, it will be in that language. Why and how? Cookies…take a look in the cookies for your browser and you will see that you now have a “fr-ca” cookie after selecting the FR language selector:

Language Cookie

Language Cookie in Firefox

So really all I am doing is just checking for certain strings in the URL and replacing them and then modifying the URL to go to the language that I want using “sc_lang=[LanguageOfChoice]”. Simple and easy!

This code can be used as a baseline to extend if needed of course. My goal here was to give you a good head start depending on your language selection needs and requirements. Happy coding!