Our goal was to have a reusable site template that could be used to provision a SharePoint site with pre-existing web parts via a workflow. We started by creating a team site, adding various web parts, libraries and custom metadata. We finished by creating a home page with a Content Search web part that would show the ten most recent documents across all libraries in the current site. We then saved this site as a template.
Next, we instructed the workflow to create a new subsite using this template whenever an item was added to a list at the root site. But after populating documents on the subsite, we found that our web part was not showing document images properly. The issue can be seen in the image below.
Problem & Analysis
The SharePoint Content Search web part does not retain all of its properties when a site is provisioned from a custom template in SharePoint Server 2013. We noticed that after templatizing the site and then using the template to create a new site, the Content Search web part did not have the expected properties.
When we compared the web part settings from a newly provisioned site to the web part properties on the original template site, we found that the Item dropdown list was set to a different value. After multiple attempts of recreating sites and making modifications to the template, we decided that it was time to crack open the site template itself. By using Visual Studio, you can open the site template and make modifications.
But, there is a quicker and easier solution.
1. Download the wsp file and rename it to .cab
After renaming it, it should look like this:
2. Extract the .cab file to C:\ using WinRar or any other unzip utility
After extracting the file, you’ll have access to the following folders:
3. Open C:\JobSiteTemplate\JobSiteTemplateModules\Elements.xml
4. Search for the content search web part, then look for the ItemTemplateId property
5. Replace the tilde (~) with the XML encoded entity ~ and save the file. After the change it should look like this:
6. Recreate the .cab file by using this two-step process:
First you need to create a DDF file. I used ddfgenerator from codeplex. Download it and run a command to generate the DDF file.
Then you will have to run the makecab utility to create the .cab file.
7. Rename .cab to .wsp and upload it to the solution gallery of the SharePoint site collection.
That’s it! Your Content Search web part should now retain its properties when creating SharePoint sites from a custom template.
It’s apparent that there is a bug in templating a site that uses a Content Search Web Part. Until Microsoft patches this, we will have to go with this manual workaround. Give it a try, share your results, and let us know if you find a better solution!
Feel free to reach out should you have questions or need help with Microsoft SharePoint.
Abdur Raheem, Senior SharePoint Consultant, FMT Consultants
Posted by: Jakob Bechgaard