Showing posts with label Customizing Quick launch in SharePoint. Show all posts
Showing posts with label Customizing Quick launch in SharePoint. Show all posts

Friday, June 13, 2014

Enabling Quick launch menu based on Site Template ID

Introduction

I am going to share my thoughts about enable the quick launch for particular site template.

Master Page Customization

First, we needs to check the .sideNavBox class in master page. This class only enabling the quick launch (left) in all the pages. On my case i need to enable the left navigation for Community sites only. So i have disabled the .sideNavBox using style.

.sideNavBox{display:none;}

Now, we are going to enable the .sideNavBox using jquery

Java Script to enable left navigation

In SharePoint, we have a var called g_wsaSiteTemplateId to find the site template. I have take that variable to check site template and enable the sideNavBox. Here the jquery script to enable the menu.

<script type="text/javascript">
    $(document).ready(function () {
        if (g_wsaSiteTemplateId == 'COMMUNITY#0') {
            document.getElementById('sideNavBox').style.display = 'block';
        }
    });
</script>

Do this script in your master page. Then, Left navigation will come based on the site template.

Happy Coding..... !!!!!!

Thursday, March 20, 2014

Modifying Quick Launch Item programmatically in SharePoint


Let me share an idea to change the "Quick Launch" item URL in SharePoint. I have taken an example like, setting the Home page URL at Site Page Feature Activation. I have written the method to set a home navigation and called at FeatureActivated event.

The method for Changing Home URL


 private void SetHomeNavigation(SPFeatureReceiverProperties properties)
        {
            SPWeb web = properties.Feature.Parent as SPWeb;
            if (web != null)
            {
                SPNavigationNodeCollection leftQuickLaunch = web.Navigation.QuickLaunch;
                foreach (SPNavigationNode item in leftQuickLaunch.Navigation.QuickLaunch)
                {
                    if (item.Title == "Home")
                    {
                        item.Url = "Your URL";
                        item.Update();
                        web.Update();
                        return;
                    }
                }
            }
        }

Then, Call this method in FeatureActivated. That's all set.