Category Archives: Did you know…

All the cool things I find out as I go along in my Sitecore development that make say, “Cool, I didn’t know that”.

Parameter Templates for Pointing to Content Items

Dynamic Parameter Templates for Pointing to Content Items

Have you ever been in a predicament, in code, where you need to point to an item in the Sitecore content tree?

For instance, you are building a Search Component, and when the user clicks search, you are going to send over the keyword/s in a query string to the Search Results Page for use in processing and displaying the results. In code, I will need that URL in my Search Component in order for me to send over the results. Let’s analyze what our options are on this scenario:

For sake of simplicity, I will leave the null checking and exception handling to you. These are simply options to get ultimately to my point:

Option 1 (Rookie Option):

var searchResultsPage = Sitecore.Context.Database.GetItem("/sitecore/content/Home/Search Results");
var searchPageUrl = LinkManager.GetItemUrl(searchResultsPage);

We can get the item using the path, then get the item URL at that point. However, we NEVER want to do this with content items! If that path changes then now you have a broken Search Component. Just because we can use paths to get items in Sitecore, doesn’t mean it’s a good practice. As a matter of fact, I would consider it bad practice all around, so steer clear of this method.

Option 2 (Better Option):

var searchResultsPage = Sitecore.Context.Database.GetItem(ID.Parse("F6778EA3-1B76-4BBF-AD21-63E9EA847FDE"));
var searchPageUrl = LinkManager.GetItemUrl(searchResultsPage);

A better method to pointing to items is with the ID using the item GUID. Why? Performance reasons. Sitecore will pick that item up faster using the ID. More importantly the ID is tied to that item ONLY and anywhere the Content Editor moves the item, Sitecore will still be able to fetch it, and nothing will break on the Search Component.

Option 3 (Even Better Option):

Typically, in most solutions that I have come across for Sitecore, there is Constants file that has ID’s in the Constants file something like this:

public class ItemIDs
{            
     public const string NewsCategoriesFolder = ID.Parse("{B866EC76-54ED-447D-9AB2-5E05A0699586}");
     public const string SearchResultsPage= ID.Parse("{F6778EA3-1B76-4BBF-AD21-63E9EA847FDE}");
}

As you can see from above there is an item for the News Categories Folder and the Search Results Page. Both of which need to be referenced in code, and the reason why they are in the Constants file. Using the method of putting those ID’s in the Constants file makes it easier to manage those ID’s in one place. When doing so, you can then get your item more clean and like so, in this case the Search Results page:

var searchResultsPage = Sitecore.Context.Database.GetItem(Constants.ItemIDs.SearchResultsPage);
var searchPageUrl = LinkManager.GetItemUrl(searchResultsPage);

If you make a change to the Item ID, then it will make that change across your solution versus having that ID out there in 5 other components you will need to change manually.

Option 4 (Best Option using TDS & Glass.Mapper with Code Generation):

Option 3 is definitely considered a best practice, but what if we can make this even easier to manage dynamically using TDS & Glass.Mapper, and keep ID’s out of the Constants file altogether except for rare circumstances?

Now that you have seen a few ways to point to the item in the Content Tree, let’s discuss Parameter Templates. Parameter templates are a way for you to add fields to your rendering that can help out the Content Editor in their daily Content Editing experience. Below are links to helpful information regarding Parameter Templates:

Now, that you have a good idea of what Parameter Templates are and how to set them up, let’s talk about why we would want to use them as a best practice in components for item pointing.

Parameter templates help to manage the solution while providing a better experience for your Content Editors. We simply create a Parameter Template to be used with the Search Component that has this criteria:

  • Name: Search Results Page
  • Field Type: DropTree
  • Data Source: /sitecore/content/Home/

We create a Standard_Values for the Parameter Template and set it to the Search Results Page by default.

When added to the Search Component, it is by default set to the Search Results page, but if the Content Editor ever wanted to point to an alternative Search Results page (for whatever reason), they now have that option. But more importantly, you bypass having to now add this to the Constants file, if your Parameter Template is strongly typed as one of your Models. Using TDS with Glass.Mapper “Code Generation”, this will allow you to create your Parameter Template for the Search Component, then have it auto-generate the Model in your solution for use where you can then call on the Parameter Template like so using Glass.Mapper (notice Search_Results_Parameter):

var renderingParameters = GetRenderingParameters<Search_Results_Parameter>();
var item = Context.Database.GetItem(ID.Parse(renderingParameters.Search_Results_Page));
var pathInfo = LinkManager.GetItemUrl(item, UrlOptions.DefaultOptions);

The Search Results Parameter is now dynamically generated anytime there is a change in the item in Sitecore. Hence, you never had a need to create the model OR add the item ID/path to the Constants file.

Keep in mind you can still do this without TDS/Glass.Mapper “Code Generation” feature, but then you will need to create a model manually for your Parameter Template. The benefit is that you have given the Content Editor the ability the point to the Search Results page versus having this functionality in code that needs to be changed by a developer, and that is the benefit to the client. To my knowledge, you can also do this same type of “code generation” functionality with Unicorn/Synthesis as well.

I have found going this route equates to maximum productivity for the development team once the concept is understood, and helps in manageability of your solution overall. Happy coding!

Rebuilding Reporting Database for Experience Profile Data

Are you familiar with the Experience Profile in Sitecore?

This is a phenomenal tool for Marketers that have audacious goals for their organization. The Sitecore marketing team talks about the Experience Profile as such, “Data-driven marketers who want a 360-degree view of their customer’s interaction with all digital channels over time and in real-time will find just that in the Sitecore Experience Profile”. If you have never taken a good look at what is possible with the Experience Profile, check it out!

Now, what does this have to do with rebuilding the reporting database? Good question! Experience Profile is completely dependent upon the Sitecore_Analytics_Index. If there is no data in the Sitecore_Analytics_Index then there will be no data in the Experience Profile. So, how does data get into the Sitecore_Analytics_Index? Let’s a take a look:

In this example using a typical model of a 1 CM (Content Management Server) with 2 CD (Content Delivery Server) environment, the CD server/s will be delivering customer experience data to MongoDB during the customer session/s. When the session/s ends, typically after 20 minutes (unless set to end earlier) then the data gets flushed using the xDB Processing Server/s. If you have not setup the xDB Processing Server/s on a standalone server then the processing will happen on Content Management server. The processing will take this data and migrate it to your Reporting database, where it will reside, and then be indexed, for performance reasons, by the Sitecore_Analytics_Index for use in the Experience Profile.

Now, why might be ever want to rebuild the reporting database and how do we even do that? Good question! If you don’t see any data in the Experience Profile, and you have a license for the functionality, then, “Houston…we have a problem”. Below are some steps to troubleshoot:

  1. Check the logs using Sitecore Log Analyzer on the Sitecore Marketplace, and see if you have any Mongo connection errors. Connectivity may either have been disrupted or never configured properly. If you are using SOLR look for SOLR errors relating to the Sitecore_Analytics_Index as well.
  2. Ensure you have MongoDB connectivity by using RoboMongo to ensure that data is truly being collected in the collections.
  3. Check the Reporting database tables to see if there is any data being collected. If not, then the xDB processing may not be working for some reason OR you have a connection string missing or incorrect to the Reporting database.
  4. Ensure if you are using SOLR that your cores are setup correctly along with configsets particularly for Sitecore_Analytics_Index.
  5. Check the Sitecore_Analytics_Index for any indexed records. More than likely you will see no records.

If you went through 1-4 and the data is all there, but still don’t have any records in your Sitecore_Analytics_Index then you are now looking at rebuilding your reporting database.

But wait, why don’t we just rebuild the index for the SItecore_Analytics_Index? Good question! Adam Conn explains this in his blog post, but we cannot manually do this, as it is done behind the scenes in Sitecore. There is a workaround to get the Sitecore_Analyics_Index to show up with the rest in the Select Search Index dialog box, but it can be problematic as Adam shows in his post.

Now is when the Rebuild Reporting Database tool comes to the rescue. When you rebuild the reporting database you also then set the Sitecore_Analytics_Index to be re-indexed through this process.

To rebuild your reporting database you will actually need to create a second reporting database to use with the Rebuild Reporting Database administration tool. Instructions on how to do that can be found here. Now, once you have a second reporting database in place you can then use this tool in the Administration Tools area of Sitecore:

Rebuild Reporting Database

Rebuild Reporting Database

When you run this tool you will rebuild the reporting database thereby re-indexing the Sitecore_Analytics_Index. At this point, you should start seeing data flow into the Experience Profile. Happy coding!

Find Text In Sitecore Files

Using Notepad++ To Find All Text In Sitecore Files In A Folder

Have you ever wanted to search for text in all files of a folder? Windows search will allow you to search through a folder, but will return the keyword in the filename by default. That’s great if you want to find a file in the folder, but what if you want to go deeper and search through all files in those folders for a certain keyword? I ran across this scenario recently, and I wanted to share with the community of Sitecore developers because it can be a very useful tool when performing some Development Operations type of tasks to help you troubleshoot when in certain situations as you will see. If you have seen this trick before then, “Amen”, but if not then make this a part of your toolbox!

Let’s just say you are troubleshooting a CD server in a typical 1 CM | 2 CD distributed environment that is having issues still referencing the “master” database. You simply want to find out where all the “master” references are in the App_Config folder and sub-folders without having to open each file manually and check. Can you imagine having to do that? As Kamruz Jaman would say, “Ain’t nobody got time for that!” Notepad++ to the rescue!

All you have to do is the following:

  1. Download Notepad++
  2. Open up Notepad++
  3. Either do a “Ctrl-Shift-F” OR click on “Search” tab then click on “Find in Files…”

    Find In Files Search Option

    Find In Files Search Option

  4. Once you click on that option you will get this “Find in Files” dialog box where you can set your settings for your search. For this example, we will set to “master” in the “Find what” text box and set the “Directory” to “D:\App_Config”. Lastly, we will just ensure the “In all sub-folders” is checked as well as seen below. Please note that you can also do a “Replace in Files” as well and even search in hidden folders:

    Find in Files Dialog Box

    Find in Files Dialog Box

  5. Click “Find All” and watch the all the goodness that returns to you!

As you will see below you now have that keyword brought to you in all the files in that sub-folder as well as the filename and path.  Not only that but when you double-click on the line item it will appear above in the text editor so you can view and modify.

Find in Files Search Results

Find in Files Search Results

With this knowledge, now you are armed like a boss to find keywords in files throughout your Sitecore development daily grind that will make you a more productive member of the team. Happy coding!

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!

3 Basic Steps to Help You Become a Sitecore MVP

At the end of the year 2014 when the Sitecore MVP’s were awarded their MVP status, it was then that I decided I wanted to become a Sitecore MVP.  Below are some simple steps that I used to obtain my Sitecore MVP status for 2015 in as little as 30 minutes a day, which is 2.5 hours a week added on to your daily/weekly routine.

I have been bodybuilding this year, and I am going to relate becoming a Sitecore MVP to bodybuilding.  Here’s the secret:

It’s all about passion and consistency!

When you walk into the gym you will almost always see the guys that are bigger and ripped.  So you ask yourself, “What are they doing to get that size and definition?”  Yes, they could be on steroids, which is what most believe, but I assert that’s not the case.  More often than not, they have just made it a habit to show up every day, and made it a point to not let anyone else outwork them in the gym.  It’s their passion, and they are consistent in showing up and working hard 5-6 days a week to reach their bodybuilding goals.

Becoming a Sitecore MVP is very similar to bodybuilding in the aspect that it’s much easier and less stressful to work on your MVP status daily/weekly.  This is a much better strategy than waiting until nominations come around in October/November of every year to start getting to work on the MVP award.  That can be time-consuming and stressful if you need to play catch up on a lot of the things that Sitecore is looking for to reward you with the MVP award.  To make this even more clear, if you relate this to bodybuilding, that’s like walking into the gym after you haven’t worked out all year long and stacking 500 pounds on chest press, and going for it.  It’s just not a smart idea!

Below is a brief list of things you should focus on when seeking to obtain the Sitecore MVP status.  The panel looks at the quality, quantity, and the level of impact of these particular contributions:

  • General (technical) advocacy
  • Contributing to the Sitecore community via blogs
  • Contributing to Sitecore Community forums (SDN forums have moved)
  • Helping others on online communities like Stackoverflow
  • Visiting and/or Contributing to the Sitecore User Groups
  • Writing and/or publishing content such as white papers and articles
  • Sitecore Marketplace contribution
  • Support tickets contribution

Consistency and involvement is key and I will give you some pointers on where you should spend your time below to help you in your quest to become a Sitecore MVP.

Step 1: Become selfless not selfish

I still remember about 6 years ago when I was the Lone Ranger in my company that just got a license for Sitecore.  I was tasked with learning and becoming the sole developer/resident expert on Sitecore 6.0.  At that time, I was a complete Sitecore rookie, and my only source of knowledge was the documentation that Sitecore provided on the SDN.  Back then there wasn’t much for Google searches when it came to troubleshooting. I struggled to take in all the information and learn on my own, but I was determined to rise up as a solid Sitecore developer. It was at that time that I vowed that should I ever become knowledgeable with the product that I would help others in the Lone Ranger situation. Hence, the reason I share my knowledge today, which is to share and give back to the Sitecore community as they have given back to me in my time of need.

Start with a selfless heart when seeking to obtain the Sitecore MVP status. Realize that most of the MVP’s would probably still do all these things even if there wasn’t an MVP program. It’s just a unique character attribute to possess where you want to help others and not keep all this information to yourself.

Step 2: Set daily/weekly goal on hourly commitment

Nothing is free.  If you want to become a Sitecore MVP or a have a healthy, fit body you simply have to commit to how much time you are going to spend to obtain that which you seek.  What I do every morning is try to wake up about 30 minutes early before work and focus on those contributions above that can help the Sitecore community.  Once you have a time commitment you can then decide where to spend that time.

Step 3: Setup this time allotment in your calendar and stick to it

Take the time to put in your calendar this time commitment so you can keep yourself accountable. When the time comes to work on knowledge sharing, hopefully, you will already have a plan of what you are going to do.  But here is what you can do with your time allotment of simply 30 minutes a day:

  • Jump on the Sitecore Community forums and/or Stack Overflow and help others to work through their issues. You may not know the answer, but maybe you can help lead someone in the right direction.  Try answering the issues or offering input where you can with your knowledge and experience. It all helps even to stir up thought that may help that person reach a final solution. Make sure to set up your notifications to come directly to your email inbox so you can see what’s new and respond promptly to ones that you previously were helping with.
  • Use this time to blog on a topic that you find would help the Sitecore community.  I usually have found that as I am working through my normal work, I have these moments where I say to myself, “I bet others could benefit from what I just went through.”  And that is the starting point of a new blog that I start while it’s still fresh in my mind. So as you are working always be thinking of what it is that you’re doing that could help others.
  • Use this time to build a Sitecore Marketplace module.  If different clients are asking for the same type of component or module and it’s not on the Sitecore marketplace consider developing a Sitecore marketplace module.  Chances are that other Sitecore clients will want to use it.  Just be ready to support it as well i.e. bugs, new features, updating to work with newer releases of Sitecore.

In addition, to what is above that you can spend 30 minutes a day on you should also get involved in the social Sitecore community via Twitter and Slack.  Slack is used to bounce ideas around on the Sitecore Slack channel.  Great to see what other Sitecore developers are talking about and get involved.  What’s best about slack is it’s real-time chat with other Sitecore developers from around the world!

If you live in a state where you have a Sitecore User Group that meets regularly get involved! Definitely show up to the meetings on a regular basis but if there is something you would like to present on then let the User Group leader know. For those of us, that live in areas where there is not a Sitecore User Group consider starting one up.  Here is a link to the Sitecore User Groups directory. Here you can see where a User Group is located near you.  For us that live in disparate areas, there is a Sitecore Virtual User Group but it’s based on presenters.  No presenters, no meeting.  Hence, another area where you can pitch in and contribute towards becoming an MVP if you feel comfortable enough to present on a topic.

Lastly, as you go about your day and encounter issues with Sitecore that can’t be resolved with your technical ability and the help of Google, then consider putting in a support ticket to Sitecore Support.  Again, chances are it’s a bug that needs to be addressed and fixed in the next release. Sitecore wants to know about all these bugs so don’t think you’re being a pain in the neck, it’s helping them to build the most solid, robust, enterprise level CMS system in the world.

So remember, do it because Sitecore is your passion and you love to share NOT because you have to.  Next, set aside time each day to make it simple and easy for yourself to reach your goal of MVP. Lastly work your plan daily/weekly to share to the best of YOUR abilities with your knowledge and expertise. Happy coding!

 

Sorting Template Sections in Sitecore

Here is a little nugget for those Sitecore enthusiasts who want the ability to sort the sections in a content item.  For years I didn’t know about this as a Sitecore Developer so if this helps just one person I have done my job to pass on this helpful knowledge.  Kudos to the guys at Active Commerce for showing me when I went through Active Commerce Certification training.  Active Commerce is a fantastic add-on to Sitecore for E-Commerce functionality and I highly recommend for businesses with lots of products that need an online storefront.  You can find out more about Active Commerce at their website http://www.activecommerce.com.

So let’s just say you have a Content Page template that has the following sections:

  • Page Data
  • Meta Data

I would like the Page Data section to come before the Meta Data section when the template is used to create a new item.  Below is what my template structure looks like:

Template Structure

Template Structure

The Content Page has the PageBase template selected as the Base Template.  The PageBase template has the _pageBase and _metaBase templates selected as the Base Templates.  Both _pageBase and _metaBase templates have the Standard template selected as the Base Template.

The following template sections are selected in this order on the PageBase template __Base template TreeView:

  • _pageBase
  • _metaBase

Being that they are selected in this order you would think that they should show up in the Content item sorted in this manner since the TreeView allows you to sort them.  However, below is what the __Standard Values for the Content Page displays:

Template Sections Order

Template Sections Order

Here is the solution to get the template sections in the order you wish.  In order to sort the sections you must set the Sortorder in the the Template Sections items.  In this case, there are 2 sections; Page Data and Meta Data as seen below:

Template Section

Template Section

The section sorting order is sorted alphabetically unless the sortorder is specifically stated using the Sortorder field in the Template Section items.  Hence, the reason Meta Data comes before Page Data (refer to Template Sections Order).  By default, the Sortorder field is set to 100 as seen below:

Sortorder Field

Sortorder Field

Depending on how many sections you want to sort you can increment these numbers to achieve the desired result.  For example, if I had 4 sections I would just add 100 to the other Sortorder fields in the respective Template Section items.  Since I have 2 sections I only need to set the other Meta Data Sortorder field to 200 and it will place that section underneath the Page Data section as seen below:

Section Sorting Order Achieved

Section Sorting Order Achieved

This knowledge can be used to help out the organization of your templates and give power to Content Editors to access the most relevant sections of items first when there are many sections in the an item.  Happy coding!