HOW TO: Customizing SharePoint AppWeb web template

This blog post is a contribution from Mustaq Patel, an engineer with the SharePoint Developer support team.

SharePoint Apps provides a great deal of flexibility and how much we can do with it. Using WebTemplate we can direct AppWeb (the SPWeb under which the App is hosted) to use any other Site Template instead of out of box “App” SiteTemplate.

All restrictions and other attributes that applies to WebTemplate in SharePoint 2010 or SharePoint 2013 sites, applies to WebTemplate in SharePoint Apps. 

For information on WebTemplate in SharePoint apps see below article

https://msdn.microsoft.com/en-us/library/fp179925(v=office.15).aspx

For WebTemplates in SharePoint 2010 see below article

https://blogs.msdn.com/b/vesku/archive/2010/10/14/sharepoint-2010-and-web-templates.aspx#webtemplate

For this walkthrough we will apply Team Site (STS#1) template to Appweb that gets provisioned when SharePoint hosted app is deployed in onprem. Below are the steps

  1. Create a SharePoint hosted App project using VS2012.
  2. Right click the project in Solution Explorer and click > Add new item > Empty Element.  Name it “CustomWebTemplate”.
  3. Go to \15\TEMPLATE\SiteTemplates\sts\xml and copy the ONET.xml file and paste it in the CustomWebTemplate folder that is created in the project as a result of the above step.
  4. Include the onet.xml to the project, make sure the deploymentType is ‘ElementFile’ in onet.xml’s properties window.
  5. Open onet.xml and we will start modifying it as below:
    1. Remove all <Configuration></Configuration> but the one with ID=0.  In WebTemplate we can only have Configuration with ID=0.
    2. Remove all <modules></modules>.  There should be no <modules> in a webtemplate.
    3. Remove <serverEmailFooter>
  6. Open the Elements.xml of CustomWebTemplate and paste below xml:
  7. Note that BaseTemplateName is the internal name of the site definition on which the web template ultimately derives.  This is the value of the Name attribute of the template element in WebTemp*.xml file.  BaseTemplateID is the value of the ID attribute of the template element in a WebTemp*.xml file.
  8. Right click AppManifest.xml and click > View Code.
  9. Before </Properties> copy below xml.
  10. Change FeatureId as per yours, it’s the ID of the feature that deploys the WSP in an App.  You can get it by double clicking the .feature file in Features folder.  This properties window has Feature ID.
  11. Also change the ID value in step 9 as per yours.  It’s the combination of Feature ID that you got in step 10 and Name of the WebTemplate in WebTemplate element in step 6.  Separate it with a hash symbol ( # ), also note the curly brackets ( {} ).
  12. Save all changes and deploy the app.  Once deployed browse the app.  You will notice that the App is now using team site template instead of App template.  You will see familiar quick navigation and site settings.

clip_image002

Hope this helps!