Custom Web Templates - SharePoint Bruger Gruppe (SPBG)

Who am I?
Anders Rask
SharePoint Solution Architect, ProActive A/S
Community moderator on
Custom Web Templates
In Visual Studio 2010
Web Templates?
 Web Templates is a new site provisioning method in SharePoint 2010
that, amongst other things, can be used with MSOL since it can be
deployed as a Sandboxed Solution
 Relatively unknown, probably due to little attention from product group
 Should be used when ever possible for branding SharePoint 2010!
Template Provisioning methods
 Site Templates
 Site Definitions
 Feature Stapling
 Provisioning Providers
 WebProvisioned event
 Web Templates
Site Templates
 A ”light” version of Web Templates.
 (Most) sites can be saved as template
 In SP2010 they are WSP solutions (not STP files)
 Can be imported into Visual Studio to become ”real” Web Templates
Custom Site Definitions
 Defacto way of customizing SharePoint in SP2007
 Many opinions on how (and if) to use them
 Best Practice to keep site def’s slim (get ID and use feature stapling)
 That means no modules in ONET.XML and as few features as possible
Feature Stapling
 Makes it possible to associate (staple) functionality to existing site
definitions when site is being provisioned
<FeatureSiteTemplateAssociation Id=”[guid]>"
TemplateName="BLANKINTERNET#0" />
 Can also have feature properties
 Scope is usually Farm, but can also be WebApp or Site
 To associate to all templates (except Blank) use Global
Provisioning Providers
 ”Hotwires” site provisioning, by only creating site collection and
database, but not apply template
class MeetingWorkspaceProvisioningProvider : SPWebProvisioningProvider
 In
{ code you then apply any template, and then apply any logic
public override void Provision(SPWebProvisioningProperties properties)
Activate features, restrict sub-templates, create subsites, set
SPWeb site = properties.Web;
= properties.Data;
add web parts...
// provision Blank Meeting Template
// do something potentially useful here
WebProvisioned event receiver
 Gives you a hook into the provisioning process to execute arbitrary
void WebProvisioned(SPWebEventProperties
 public
Event isoverride
(but a good idea to set to Synchronous
to avoid
{race conditions)
ThmxTheme theme = ThmxTheme.Open(properties.Web.Site,
can have Site or Web scope
theme.ApplyTo(properties.Web, false);
called for every sub-site created in the site collection
}Web: called only for the sub-sites that are immediate children of
site where receiver is called
 Usage example: set Theme on sub-sites, add web parts... etc
Web Templates
 Created in Visual Studio as Element
 No direct tool support yet, but not much to it…
 Custom ONET is injected instead of referenced site definition, so no
link to provisioned sites
 Scope can be Site (Sandboxed Solution) or Farm (Trusted solution)
 Supports publishing framework
What provisioning method is right?
”It Depends!”
 Use the right tool for the job
 Often a combination is the right solution.
 The customizations you want to do often dictates approach.
 Use Web Templates whenever possible!
Time for…
Common ”gotcha’s” creating Web Templates
Since stapling is not supported, be aware that features that would normally be
stapled on an OOB site definition must be activated manually (e.g. Taxonomyfield
Web Template and the element it resides in must have same name
If your Web Template has site scoped features, you must ensure these are
activated when using template on sub-webs
When provisioning sub-webs with PowerShell using Sandboxed Solutions you
need to provision in two steps: 1) Create web, 2) Apply template
Known issues:
Doesn’t work with variations and content publishing
Subweb and Locale doesn’t work!
Bug if OS regional settings and installed language isn’t the same and
provisioning “outside of UI” (Visual Studio or PowerShell)
“Race conditions” with Content Type provisioning (CT hub)
Good Web Template practices
 Save the custom template name in a property bag on the SPWeb for
future reference
 Ensure your site scoped features for example by calling them from web
feature in ONET.XML
 Use Visual Studio –not save Site as Template- to create Web Templates
 Check what features are normally stapled to the OOB site definition you
are mimicking and add them last at appropriate scope in ONET.XML
Key take-aways
 Web templates is just a new way of provisioning sites in SharePoint
 Prefer them over Site Definitions 99% of the time:
 B2B upgrades is easy (no link to manifest)
 V2V upgrades will be easier
 Works on SharePoint Online
 Scope is either Site (Sandbox) or Farm (Trusted) solutions
 Does not work with Site Variations, Content Publishing or similar sites
where template selection is out of your control (think Meeting
templates, My Sites etc)
Mirjam van Olst: Using Web Templates to create Site Collections
Supported and unsupported scenarios for working with custom site definitions
Vesa Juvonen: SharePoint 2010 and web templates
Robert Bogue: Understanding SharePoint Branding Options
Brian Wilson: Site Definitions versus Site Templates and deciding on
the correct customization approach
New Event Binding Functionality in SharePoint Foundation 2010
Thanks for attending session!
Thanx for attending!
See you at 
Visual Studio 2010 SharePoint Power Tools
Templates and extensions that provide a sandboxed Visual Web Part together with enhanced support for
sandboxed compilation to help you develop SharePoint solutions even more productively.
Mavention Cancel Adding SharePoint Project Items
Disables the default behavior of automatically adding SharePoint Project Items to Features.
CKS - Development Tools Edition (Server)
The SharePoint 2010 Visual Studio 2010 Extensions project (CKSDEV) is a collection of Visual Studio
templates, Server Explorer extensions and tools providing accelerated SharePoint 2010 development based
on Microsoft's new SharePoint 2010 development tools.
Imtech Get SPMetal Definition Extension
Installs a Site Node Extension that allows you to generate the SPMetal Definition from the given SharePoint

similar documents