Web part to display all community sites in a site collection, with details,
http://en.share-gate.com/blog/sharepoint-2013-content-search-site-portal
If you took a peek at SharePoint 2013 recently, you may have noticed there is a new Site Collection called the Community Site Portal. This new site works in conjunction with the Community Site template. In short, it’s a site that shows you a list of all Community Sites. My goal is to do the same thing but for other types of Sites, for example a Team Site portal.
Reverse engineering
Best way to understand how SharePoint works is sometimes to dig in to what is presented in front of us. Something quickly jumped at me when I looked at the Community Site Portal, there is a “number of results” shown at the bottom of the page and changes made to the Community Site do not appear immediately. My first thought is that it must be based on the new SharePoint 2013 Search engine. As I mentioned in a previous article, we can leverage the power of search now with the
Content Search Web Part or the Search Results to build our sites.
Let’s begin by editing the page and see how this has been built:
As you can see, the portal is nothing more than the result of a Search Query. It looks like the Content Search Web Part was added with a pre-configured Search Criteria and a custom Display Template. All we need to do now is take a look at the default Query and adapt it to our needs.
The default Content Search Criteria for the Portal
Essentially there is no manual search here; the Web Part is configured with a Search Criteria or a query if you want to display the Community Sites below. We can try to understand it a little better by clicking on the Change Query button in the Web Part properties.
Then we will have the new SharePoint 2013 Query Builder that is used in many Search Web Parts and settings. Within the Query Builder, we can see right away how it is able to get all the Community Sites for the Portal. And frankly, I am surprised at how easy it is to get it.
The Query simply says to grab “WebTemplate:Community”; in other words go get all the Sites that are built with the WebTemplate called Community.
Making a SharePoint 2013 Team Site Portal
My first objective is to change the query for the Web Part to something that will get only Team Sites instead of Community Sites. What I did is created a new Site Collection to do my tests based on the Team Site Template. I then Activated the Publishing Infrastructure Site Collection Feature. Finally I created a blank Wiki page in Site Pages and added the Content Search Web Part on it.
I jumped to the Query Builder of my new Content Search Web Part and doing something I covered recently in “
Rolling up SharePoint Sites with Content Search” I erased the Query Text box with whatever query was there by default. Then in the Keyword Filter dropdown menu, I selected the “Return Only Sites” option.
Why am I selecting this Keyword Filter?
That’s an excellent question, technically I could just modify the “WebTemplate:Community” by one that represents the Team Site WebTemplate.
In this scenario, I am assuming that we do not know what the WebTemplate names are.
By selecting this Keyword Filter and only returning sites, we can jump to the “Refiners” tab in the Query Builder at the top and let SharePoint do the work for us.
Awesome! Now I know how to write the value for my Query Text. Instead of using “WebTemplate:Community” I can try “WebTemplate:STS” for Team Sites for example.
Let’s go back to the Query Text box and type in our new value:
Let’s try it out, click on Ok and Save or Apply your changes to see your page again.
Now you can build your own SharePoint 2013 Site Portal based on any Site Template you want to. You could even push this even further by customizing the Query with other Site Properties. The issue is always in finding what these properties are.
Let’s see if it works with our Blogs as well:
WebTemplate:BLOG
I am really happy to see how easy it to change the Content Search, even as a Power User I can see this being very helpful to many.
Making it look like the Community Portal – Using the Display Templates
So we managed to build our own SharePoint 2013 Site Portal for Team Sites or even Blogs. But something is missing, the look and feel of the Portal. In my previous post on
the Content Search, I already talked about Display Templates and how to change the property mapping to put the values of the properties we want in our favorite Display Template.
Unfortunately, none of the default Content Search Display Templates matches the look and feel we got from the Community Portal. So I am going to cheat and do something I learned with the Content Query Web Part back in SharePoint 2007 and SharePoint 2010. The trick is to export the Web Part found on the Community Portal on to your Desktop and Edit it with Notepad. I noticed that it gets it’s Display Template for items in a System folder of the Site Collection Catalog.
~sitecollection/_catalogs/masterpage/Display Templates/System/Item_CommunityPortal.js
I have a few options; I can export my Content Search Web Part and add the same links for the same properties as the ones in the Community Portal. I can Copy Paste the Display Template from the System folder to Content Web Parts in the Display Templates folder. Obviously I do not recommend the ladder but I do understand that sometimes we just do not have the luxury. You can also go directly to the Display Template stored in the System folder of the Display Templates and change the hidden value from 1 to 0. You will then be able to use it in your Content Search.