Feature/Site Template Association

Applies to: SharePoint Foundation 2010

Feature/site template associations allow you to associate new Features and functionality with existing site definition configurations so that, when sites are provisioned, the Features are automatically included in provisioning. Two Features are involved in a Feature/site template association: the Feature containing the functionality you want to add to an existing site definition configuration, and the Feature/site template association Feature itself, usually declared at the farm or Web application level, which binds the first Feature to the configuration.

Important

Features can be activated on a site without a site template association. In this case, you must choose the Site Template by using the Template Selection page at http://myserver/_layouts/templatepick.aspx.

Possible scopes:

  • Farm: Yes

  • Web Application: Yes

  • Site Collection: Yes

  • Web Site: No

Example

The following example shows the format of the Feature.xml file for a Feature/site template association:

<?xml version="1.0" encoding="utf-8" ?>
<Feature Id="82E2EA42-39E2-4B27-8631-ED54C1CFC491"
  Title="Feature_Title"
  Description="Feature_Description"
  Version="12.0.0.0"
  Scope="Farm"
  xmlns="https://schemas.microsoft.com/sharepoint/"
  DefaultResourceFile="_Res">
  <ElementManifests>
    <ElementManifest Location="Feature_Elements.xml"/>
  </ElementManifests>
</Feature>

The element file for the preceding Feature.xml file might look like the following:

<Elements xmlns="https://schemas.microsoft.com/sharepoint/">
  <FeatureSiteTemplateAssociation Id="29D85C25-170C-4df9-A641-12DB0B9D4130" TemplateName="STS#0" />
  <FeatureSiteTemplateAssociation Id="29D85C25-170C-4df9-A641-12DB0B9D4130" TemplateName="STS#1" />
  <FeatureSiteTemplateAssociation Id="29D85C25-170C-4df9-A641-12DB0B9D4130" TemplateName="BDR#0" />
  <FeatureSiteTemplateAssociation Id="29D85C25-170C-4df9-A641-12DB0B9D4130" TemplateName="SPS#0" />
</Elements>

You can also globally associate a Feature with all Web site creation through all-site definitions on the front-end Web server. Associate the Feature with the global site definition by specifying GLOBAL for the TemplateName attribute. Whenever you create a site the global site definition is applied, and so your Feature will also be applied.

For more information, see Feature/Site Template Associations.