Surendra Sharma

Surendra Sharma

Search This Blog

Showing posts with label Helix. Show all posts
Showing posts with label Helix. Show all posts

Friday, January 18, 2019

4th Sitecore Marketplace Module – Sitecore Social Feeds Manager

Sitecore Social Feeds Manager
Sitecore Social Feeds Manager

I am very excited to share my 4th module “Sitecore Social Feeds Manager” on Sitecore marketplace. You can download it from here.

We all know the importance of social media for product branding. Almost all websites showing their organization or products related social messages to their website.

I created this helix-based module for getting social feeds from Facebook, Twitter, Youtube and Instagram.

Steps to use this module
1. Download and installed this Sitecore package
2. Fill your Social keys for Facebook, Twitter and Youtube in item "/sitecore/content/Habitat/Global/Social/Social Media Manager"
3. Publish Sitecore items.
4. Access JSON result from URL http://<your.sitecore.instance>/api/sitecore/social/GetSocialFeeds?channelName=youtube&token=accesstoken.

By default, it shows recent 8 feeds from each social channel but you can control the number of feeds from Sitecore.

I also included “All” feeds option where you can access recent 2 feeds from each channel and show mix of total 8 feeds on your front end. Again, you can control total numbers of feeds from Sitecore for “All” use case.

I have excluded HTML part on this module as every website have different HTML and look and feel. So directly consume this JSON output and integrate it in your HTML at desired location.

A sample HTML for calling and using this JSON data by AJAX is

<div id="SocialFeedsDiv">

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

    <script>


        $(document).ready(function () {
            var b = null;
            $("#all").click(function () {
                loadfeeds("All")
            });

            $("#Facebook").click(function () {
                loadfeeds("Facebook")
            });

            $("#Twitter").click(function () {
                loadfeeds("Twitter")
            });

            $("#Youtube").click(function () {
                loadfeeds("Youtube")
            });

            $("#Instagram").click(function () {
                loadfeeds("Instagram")
            });


            function loadfeeds(channelName) {
                $.get("/api/sitecore/social/GetSocialFeeds?channelName=" + channelName + "&token=accesstoken", function (data, status) {
                    var index = 1;
                    $("#feedlist").html("");
                    $.each(data.responseResult, function (i, field) {
                        var imageurl = "";
                        if (field.ImageURL !="" || field.ImageURL != null) {
                            imageurl = "ImageURL : <a href='" + field.FeedURL + "' ><img src='" + field.ImageURL + "' alt='" + field.Title + "' /> </a> <br>";
                        }
                        $("#feedlist").append(
                            "<li>Sr No :" + index + "<br>" +
                            "FeedID :" + field.FeedID + "<br>" +
                            "PlatformName :" + field.PlatformName + "<br>" +
                            "Title :" + field.Title + "<br>" +
                            "Description :" + field.Description + "<br>" + imageurl
                            +
                            "FeedURL :" + field.FeedURL + "<br>" +
                            "Timestamp :" + field.Timestamp + "<br>" +
                            "From :" + field.From + "<br><br><br>" + "</li>"
                        );
                        index++;
                    });
                });
            }
        });

    </script>

     <br />
    <a href="javascript:void(0)" id="all">All</a><br />
    <a href="javascript:void(0)" id="Facebook">Facebook</a><br />
    <a href="javascript:void(0)" id="Twitter">Twitter</a><br />
    <a href="javascript:void(0)" id="Youtube">Youtube</a><br />
    <a href="javascript:void(0)" id="Instagram">Instagram</a><br />

    <div id="feed">

    </div>

    <br />
    <br />

    <div id="HTMLfeed">
        <ul id="feedlist"></ul>


    </div>

</div>

You may interested in my other 3 modules on Sitecore marketplace




I hope you will use these Sitecore modules. Stay tuned for more Sitecore related information.

Till that happy Sitecoring :)

Please leave your comments or share these marketplace modules if it’s useful for you.

Monday, December 3, 2018

Sitecore 9.1 making HELIX as de facto standard for website development

I installed Sitecore 9.1 and notice this change in content tree. You should get Foundation, Feature and Project items under layout, rendering and template in content tree.

I have not observed this in earlier versions of Sitecore 9.

I suppose Sitecore is pushing HELIX guidelines as de facto standard for all Sitecore website development.


Happy to see these items in Content tree.

Foundation, Feature, Project items in Sitecore 9.1
Foundation, Feature, Project items in Sitecore 9.1

Monday, January 8, 2018

Fix : Duplicate controller Issue in Sitecore Helix project

If you are working in Sitecore Helix Framework and going to call action method like  http://myinstance/api/sitecore/accounts/RenderResetPassword, you may get error like

Server Error in '/' Application.

Multiple types were found that match the controller named 'accounts'. This can happen if the route that services this request ('api/sitecore/{controller}/{action}') does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the 'MapRoute' method that takes a 'namespaces' parameter.

The request for 'accounts' has found the following matching controllers:
Feature.Abc.Accounts.Controllers.AccountsController
Feature.Xyz.Accounts.Controllers.AccountsController

It’s because of duplicate controller name in Abc and Xyz project.

To fix this, we have to register custom MVC routes in Sitecore. For this, I created one custom processor file “RegisterCustomRoute.cs” to initialize pipeline.

You have to register your duplicate controller as

    public class RegisterCustomRoute
    {
        public virtual void Process(PipelineArgs args)
        {
            RouteTable.Routes.MapRoute
                ("AbcAccount",
                "abc/{controller}/{action}/{id}",
                new { controller = "Accounts", id = UrlParameter.Optional },
                new[] { "Feature.Abc.Accounts.Controllers" }
                );

            RouteTable.Routes.MapRoute
                ("XyzAccount",
                "xyz/{controller}/{action}/{id}",
                new { controller = "Accounts", id = UrlParameter.Optional },
                new[] { "Feature.Xyz.Accounts.Controllers" }
                );
                        }
    }

Here I have append “abc” and “xyz” to separate the URL for account and specified their Namespace as last parameter in MapRoute() method.  Now you can call new URL as

With this you don’t need to put “api/sitecore” in URL now for accounts controller.

I registered this Processor entry in config patch file customweb.config

    <pipelines>
      <initialize>
        <processor type="MyProject.Website.RegisterCustomRoute, MyProject.Website" patch:before="processor[@type='Sitecore.Mvc.Pipelines.Loader.InitializeRoutes, Sitecore.Mvc']" />
      </initialize>
    </pipelines>

If you are facing the same error, make sure to add entry in “RegisterCustomRoute.cs” as highlighted above.