During Sitecore Helix development it’s important to understand the role that template inheritance plays in keeping your dependencies in check.
The current conventions shown in the Habitat example site is to:
- Create your template fields in modules within the foundation and feature layers with templates starting with a ‘_’.
- Inside the project layer, create appropriate templates that inherit from the feature and foundation layer templates.
Each project layer template should inherit from one or more feature / foundation layer templates.
We believe the benefits of sticking to this approach are as follows:
- Your project layer templates can be composed of template fields from multiple modules in other layers. With the potential for page templates to contain the functionality from multiple modules if need be.
- Your content tree does not directly rely on feature and foundation layer templates making their removal down the track easier if need be.
Data Source Locations
Helix introduces the concept of Data Source Locations which are documented on this page.
Data source locations are very useful for supporting multi-tenant, multi-site solutions. You don’t have to use them, however using them does future proof your Helix solution with the ability to add additional tenants down the track.
The datasource location and template resolution have been extended in the Habitat project. This means that it is also possible to define datasource templates and locations for each site, in addition to on the rendering itself. This is done through an extension of the getRenderingDatasource pipeline and the addition of a site: prefix to the Datasource Location field.
The above IFrame rendering uses the syntax site:iframe which via the getRenderingDatasource pipeline will look for a data source location within the site called ‘iframe’.
This is great for multi-tenant situations but it also means that the helix dependency rules are not broken. Pointing the data source location field of your rendering to a folder within a website technically breaks the Helix dependency rules. This is a very important point and one that might be missed on a first pass through the Helix documentation.
The trap of using Feature Templates
Developers that are new to helix may not realise that any feature layer modules should have a matching template in the website layer that inherits from the feature layer.
A follow-on effect from this is that you may skip the creation of a project layer template altogether and simply use the feature layer template in the “Datasource Template” field.
Technically the above dependency is not incorrect. Habitat has one more surprise install for you, however. Once you start to add content blocks to your page based on the data source locations, your insert options for the Local data sources folder start to get automatically populated.
So for each unique component, you add to the page via Experience Explorer your going to get the template of that component in the insert options.
once again this dependency is not technically incorrect, although it will probably have your testers asking why strangely named templates are showing up in the insert options. The major drawback we could think (as mentioned earlier in the article) is that your content items will be highly dependent on that particular feature module.
- You will have multiple dependencies between content items and the feature modules.
- Attempting to remove the feature layer will disrupt all of those content items directly.
On the flip side using the project template instead, means we have a single (or reduced) point of removal for that feature module within the project templates.
The main takeaway we took by running into the above mistake (using the feature template in our data source locations) was that we should be pointing the data source locations at a project template instead.
- Always create a project layer template that will inherit from a feature/foundation module template.
- Ideally content items shouldn’t reference feature layer templates directly, even though this doesn’t break the helix dependency rules.