Friday, July 19, 2013

SharePoint 2013 - Display description of the site





When you are creating new site collection or new site in SharePoint 2013, you need to write name of the site, its URL, and administrator. Also, you have possibility to enter some short description of the site. But, after the site is created, this description isn't visible no where on the site.
You can make it visible by adding new web part on the page which contains simple javascript code that will show your description.

First, I will create new site with some description:


Now, open your site on which you need to add description and click on Settings --> Edit Page:


In SP Ribbon click on tab "Insert" and then click on button "Web Part". Add new web part called "Script Editor" from "Media and Content" category:




Edit that Web Part and copy following script in it:

<script>
       _spBodyOnLoadFunctionNames.push("GetSiteInfo");
       var site;
       function GetSiteInfo()
       {
            var ctx = new SP.ClientContext.get_current();
            site = ctx.get_web();
            ctx.load(site);
            ctx.executeQueryAsync(onQuerySucceeded, onQueryFailed);
       }
       function onQueryFailed(sender, args) {
            alert('request failed ' + args.get_message() + '\n' +  args.get_stackTrace());
       }
       function onQuerySucceeded(sender, args) {
            var desc = document.getElementById('divSiteDescription')
            desc.innerHTML = site.get_description();
       }
</script>


<div id='divSiteDescription'></div>



Save Web Part changes and save changes made on the page by clicking button "Save" in SP Ribbon.

Now, you can see the description of your site on the page: