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:




7 comments:

  1. If you can edit the master page then it is even simpler, add <SharePoint:ProjectProperty runat="server" property="Description"> wherever you want the description to appear.

    ReplyDelete
    Replies
    1. Even better solution. Thanks.

      Delete
    2. I would love to put this in the master page, which I can edit, but I am finding that simply pasting in your snippet of code into the desired spot is insufficient. I would like it to appear right under the title, but if I insert that code under the line nothing shows up on the page.

      Delete
    3. Have you tried to debug the code in your browser (F12), do you get any error? It is possible that script sp.js isn't loaded on the page when the script is executed. Try replacing the line:
      SP.SOD.executeFunc('sp.js', 'SP.ClientContext', GetSiteInfo);
      instead of:
      _spBodyOnLoadFunctionNames.push("GetSiteInfo");

      Delete
  2. Does not display for me. The Script Editor shows description of the site but is not displayed on site page.

    ReplyDelete
    Replies
    1. Have you tried to debug the script (F12) and see does it get the site, does it execute the script at all?

      Delete
  3. This is great for displaying the description of the sub site. How would you go about doing this to display the descriptions of individual lists and libraries?

    ReplyDelete