Facebook Feed Widget in Sitecore Habitat


In the previous post we have a introductory view on what Sitecore Habitat is. In this post we will get our hands dirty creating a Facebook Widget in Sitecore Habitat.

Out of the box, Sitecore Habitat contains number of Features. One of the Features is “Social” and we will use Sitecore.Feature.Social project in Habitat solution for Facebook Feed Widget. Before we get started, let’s examine what is available in Sitecore.Feature.Social project.


From here we can see that Social comes with certain implementation for Twitter feed. If we visit our Habitat instance, we can see there is a Twitter feed shows in the following page:


From here, we will create a Facebook feed to replace the Twitter feed.

First step, we create a new data template to cater for the fields for Facebook feed.


Click on image for full size view

Then, we create an item in Content Editor named FacebookDetails for setting the actual properties for the Facebook feed. In this example, we are using Sitecore Facebook page for demonstration purpose.


Click on image for full size view

The complete properties are as following:

FacebookUrl: https://www.facebook.com/Sitecore
Type: timeline
Width: 350
Height: 600
Hide Facebook Cover: [unchecked]
Hide Face Pile: [checked]
Title: Sitecore Facebook Feed

Type is a Droplist. Facebook feed supports multiple types, namely timeline, events and messages. By having Type as a Droplist, user can select which kind of feed to fetch from Facebook. However for simplicity sake, you can also configure your Type as a Single-Line Text. Doing that you will have to type in the Type field yourself each time you were to change the feed type. Not a show stopper, but something nice to have 🙂

Next, we will move to Visual Studio to tie the fields to a FacebookFeed View that we are about to create.

Look for Template.cs under Sitecore.Feature.Social project. Add the following struct into the class. Do note that the GUID in your instance will be different from the GUID displayed here if you are creating the fields by yourself. Hence, remember to replace the GUID in these properties. If you installing the Sitecore package provided at the end of this post, the GUID will remain the same.

    public struct FacebookFeed
      public static ID ID = new ID("{BDD24F35-05E8-4466-8798-7D3DD6A6C991}");

      public struct Fields
        public static readonly ID Title = new ID("{444917D1-822E-413F-A5C2-546C8689904A}");
        public static readonly ID FacebookUrl = new ID("{CACE8D98-ACD7-46C8-86AE-436C99AAB71F}");
        public static readonly ID Width = new ID("{6097D9A2-183E-4918-8E76-EFF3789529D9}");
        public static readonly ID Height = new ID("{41BB617C-624D-4151-97B3-CD088857EB76}");
        public static readonly ID RenderType = new ID("{3F1816F5-10D8-4399-B81C-855395A86F90}");
        public static readonly ID HideFacebookCover = new ID("{A388455B-8C89-4C36-9005-8191606CADA0}");
        public static readonly ID HideFacePile = new ID("{D8FC7F17-DDD9-4A6E-A170-CCC62F32EA61}");

This is the code that “tie” the fields we created earlier in Content Editor. The next thing we will do is to create a view that consume these properties’ GUID.

Add a new FacebookFeed View in Sitecore.Feature.Social project under Social folder.


Add in the following code to construct a Facebook Feed widget.

@using Sitecore.Feature.Social
@using Sitecore.Foundation.SitecoreExtensions.Extensions
@model Sitecore.Mvc.Presentation.RenderingModel

@if (Model?.Item != null)
    <div id="fb-root"></div>
        (function (d, s, id) {
            var js, fjs = d.getElementsByTagName(s)[0];
            if (d.getElementById(id)) return;
            js = d.createElement(s); js.id = id;
            js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.5";
            fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'facebook-jssdk'));

    <div class="teaser teaser-default news-teaser">
        <div class="teaser-heading">

        <div class="fb-page"
            <div class="fb-xfbml-parse-ignore">
                <blockquote cite="@Model.Item.Fields[Templates.FacebookFeed.Fields.FacebookUrl].Value">
                    <a href="@Model.Item.Fields[Templates.FacebookFeed.Fields.FacebookUrl].Value">

Note all the HTML attributes are the fields we created earlier in data template and the values are the fields we filled in FacebookDetail item in Content Editor.

Now, compile the solution (or project). Ensure that FacebookFeed.cshtml and Sitecore.Feature.Social.dll are copied over to your Sitecore instance. Again, if you are installing the package provided at the end of this article, you will not need to copy the files over.

At this point, we have successfully created created a Facebook Feed Widget. However the widget has not been configured to display on any page on our instance. Now let’s create and configure the necessary items in Content Editor for our Facebook Feed Widget.

Create a view rendering item to represent the View (.cshtml) we have created earlier.

Click on image to view full size

Click on image to view full size

Add FacebookFeed rendering view into Layout that we want to display the View from. For simplicity sake, we use “col-wide-1” as this layout is readily available on Social page.


Click on image to view full size

Next, we will now move to Experience Editor to replace the Twitter Feed with Facebook Feed Widget we have just created.

Navigate to Social page using Breadcrumb and remove the existing Twitter Feed.


Add the new Facebook Feed into the page. Check the “Open the Properties dialog box immediately” option:


Click on Browse under Data Source:


Select FacebookDetails and click OK


On your browser, navigate to http://habitat.local/en/Modules/Feature/Social and Facebook Feed Widget will appear in your page:


Obviously, this is the most perfect Facebook Feed Widget we can build (just kidding!). You are welcome to modify any steps to cater for your own Sitecore instance.

The objective of this article is to guide you through the steps in creating a Facebook Feeds Widget in Sitecore Habitat. If you would like to have a Facebook Feeds Widget in Sitecore Habitat without going through (most of) the steps, feel free to download and install the ready made package.

Download Sitecore-Habitat-Facebook-Feed-Widget package.

Sitecore Habitat


Sitecore released Habitat on 18th December 2015. Habitat is a Sitecore solution example built on a modular architecture. Habitat architecture and methodology focus on few main concepts which are Simplicity, a simple, consistent and discoverable architecture. Flexibility, the ability to change and add quickly and without worry. Extensibility, the ability to simply add new features without steep learning curve.

Sitecore Habitat is a new “demo” site provided by Sitecore. Prior to that there is LaunchSitecore.net which is another Sitecore “demo” site where public can evaluate what Sitecore is capable of. The major difference between LaunchSitecore and Habitat is that LaunchSitecore is designed to allow public to explore the core functionalities in Sitecore, while Habitat is a modular architectural solution to build features.

To get a quick look and feel what Habitat is about, you can download Sitecore Habitat package and install it on your local Sitecore instance. Once installed, your Sitecore instance home page will have the following look:

sitecore habitat homepage

Now, let’s dive a little deeper into Habitat code base. You can clone a new repository of Habitat from GitHub.

Once cloned, you will see from Visual Studio there are 37 projects in the solution. The “magic” of Habitat sits at the Feature folder. 14 features are provided out of the box (at the point of writing). They are: Accounts, Demo, Identity, Language, Media, Metadata, Multisite, Navigation, News, PageContent, Person, Search, Social and Teasers.

sitecore habitat feature

The idea of the Habitat architecture is you can develop or use a feature independently. If one feature is broken, you can simply not use it and it will not affect the rest of the feature. Each feature has the consistent architecture to allow development practices to be more predictable.

If you are into developing a feature in Habitat, I highly recommend you to look at the videos prepared Thomas Eldblom on:

Sitecore Habitat Architecture – Introduction

This video explains how Sitecore Habitat is solution framework that focuses on streamlining development process and optimizing productivity. It also explains the how productivity is increased when developers simplify coupling.

Sitecore Habitat Architecture – Modules

This video explains the closure principles in Sitecore. It digs down deeper into Habitat code base by using Navigation as an example. It explains the Views, Controllers, Data Model and how the items are structured and how do they get built.

Sitecore Habitat Architecture – Layers

Focus on the layered architecture and how to couple modules to build the entire solution. It also explains how different layers fit together as a solution and how different modules and layer interact with each other.

This is a quick introduction to Sitecore Habitat. If you would like to find out more, feel free to visit the Habitat Wiki page.

On the next post, we will dive a little deeper into the code base to build a Facebook widget in Sitecore Habitat.