only My site

Friday, December 28, 2012

Feature Stapling / Feature Site Template Association

This is a very useful in many situations. For Instance, you need to activate a feature while creating a web site or sub site using some site template. The feature may have some functionality such as copy files from site collection style library to the newly created sub site, or Change the welcome welcome page and master page on creation of the site etc..

Feature stapling is the only solution as of now. The MSDN resource is good and the link is here

The following are the main points
1. We can associate a feature with one or multiple site templates
2. Feature will work for the newly created sites and not for the existing sites. Need to use some othe way for older sites.
3. Causes the attachment of a Feature to all new instances of sites that use a given site definition, without modifying the site definition or creating code routines to activate the Feature on each site. Also known as a feature site template association,
4. Another example : A developer creates a Feature and to add it to every new Web site that is based on a specific site definition. The developer creates a feature-stapling Feature that includes mappings between the Feature and site definition.
5. Technical Details : Feature stapling is implemented through a Feature that is specifically designed to staple other Features to one or more site definitions. Feature stapling allows a Feature to be stapled to any new sites created from any site definition or from specific site definitions based on the template name identified in the appropriate WEBTEMP.xml file.
6. Example

Following is an example of feature stapling that associates the Feature with only the STS site definition templates.

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
   <FeatureSiteTemplateAssociation Id="00BFE171-1B17-4F72-28CB-1171C0140130" TemplateName="STS#0" />
   <FeatureSiteTemplateAssociation Id="00BFE171-1B17-4F72-28CB-1171C0140130" TemplateName="STS#1" />
   <FeatureSiteTemplateAssociation Id="00BFE171-1B17-4F72-28CB-1171C0140130" TemplateName="STS#2" />
</Elements>

Following is an example of feature stapling that associates the Feature for all site definitions

<Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <FeatureSiteTemplateAssociation Id="00BFE171-1B17-4F72-28CB-1171C0140130" TemplateName="GLOBAL" /> </Elements>

No comments: