Sitecore Templates best practices
Template is data definition, it is building block for item creation. Hopefully you are aware with template creation.Here we discuss some best practices for template creation:
- Use Data templates for normal data entry templates. Use Branch templates when you have a predefined structure of items, subitems to be created.
2. Place the section of fields that are modified frequently at the top of the data template or place them in order they appear on pages. This would facilitate easy modification of the fields by Content editors.
3. Make the field names unique between sections, do provide a prefix, suffixes indicating types, for example Title Name, Product Name as field name to avoid conflicts in field names when the templates are inherited by another template.
4. Group the fields into logical sections based on business sections or data type sections thereby avoiding a huge form, and provide for a compartmentalized form, that can be collapsed as needed.
5. If you are following Helix principles, create first interface template say for example if it is related to navigation component create at Navigation Feature. All interface template name start with “_” ex: _Navigation.
Make basic template components, which then can be inherited by other templates to provide for foundation templates. This would provide for reusable and consistent data templates.
For example:
i) Create Breadcrumb template inheriting the Standard Template having Breadcrumb Title (Single-Line Text) field.
ii) Create Navigation template inheriting the Standard Template having Navigation Title (Single-Line Text), Show in Navigation (Checkbox), and Show in Sitemap (Checkbox) fields.
iii) Create PageTitleandText template inheriting the Standard Template having simple Title (Single-Line Text) and Content (Rich-Text) fields.
iv) A Foundation template inheriting the Standard, Breadcrumb, Navigation, and PageTitleandText templates.
v) Homepage template inheriting the Standard, Navigation, and PageTitleandText templates Page Link template will be inheriting the Standard, Navigation templates having link (General link) field.
6. For Checkboxes, compare with 1 to check whether the checkbox is selected or not.Sitecore stores a blank value; therefore, it is not right to check against NULL, String Empty, or 0.
7. Use TreelistEx in comparison to Treelist, in scenarios where you need read-only view and don’t need much editing. Use TreelistEx if editing frequency is lower and need read only view of the source items.Treelist will load all items when rendering,while Treelistex will load items based on user interaction.
8. Use Droplink and Grouped Droplink instead of Droplist and Grouped Droplist. Droplist and Grouped Droplist Field Types store dropdown values by item name, while Grouped Droplink stores values by item GUID.
9. Have default values in the form of standard values. This would provide for default values for the fields.
10. Consider a scenario of applicability at item level with thousands of items. In such a case, any change in these settings would be a humongous task to make changes to these items. In a scenario when it is applied at template level, these setting changes can be easily changed at Standard Values.
Flow for _Standard Values creation:
Builder Tab -> OPTIONS -> click on Standard values.
11. Centrally manage the layout settings, initial workflow, Insert Options in template standard values than in individual items.
12. Use icons wherever applicable to facilitate visual differentiation. Use of appropriate icons will cause clear distinction of different content types visually.
13. Provide proper context sensitive help for the fields, and sections in templates. This would provide for ease of use for content editor experience.
14. Use Tilda (~) character in source for image fields with caution, as this will allow the user access to the entire media library tree. Restricting use of ~ and assigning to specific folder for asset elements would make it easy for content editor to upload to respective directory, rather than from being confused with option to select the folder to upload.
15. Avoid modifying templates in Sitecore/Templates/System section. These templates are standard Sitecore templates and are part of core system.
16. Avoid using a lot of RTE fields within the template and keep the templates small. A lot of RTE fields cause performance impact when loading in page editor.
17. Avoid Circular Inheritance in templates. Example: C inherits B, B inherits A, A inherits C. Circular reference would cause for infinite recursion.
Hope this is useful tip. Happy reading :)