Start of Main Content

The Challenge

Sitecore template items that we create for pages are often made up of smaller component templates that we often call “base templates.” Base templates may be included on many different types of pages, i.e. the home page, a listing page for news articles or press releases, or a general content page like “About Us."  We think of Sitecore template items as being similar to classes; thus the page template items inherit from the base template items.

I recently came upon a challenge where fields in a base template were required to have a value in certain inheriting page templates, but not required in other inheriting page templates. The project specification looked similar to this:

7.2 Thumbnail Content Listing

Fields:   Thumbnail Listing Title - Single-Line Text

Thumbnail Listing - MultilIist

This listing is required on Home Page, required on Topic Section Listings, allowed but not required on Non-Topic Section Listings

The Solution

In order to create these components as base templates, but have required validation in some inheriting templates and not others, I made use of the field, Suppressed Validation Rules, on the page template’s Standard Values item. The Suppressed Validation Rules field is new as of Sitecore 6.4.

First, after creating the templates, I duplicated the standard field validator “Is Required” (right-click on the System/Settings/Validation Rules/Field Rules/Required item and select “Duplicate”) and named it “Thumbnail Is Required.” I did that because when you suppress a field validator, Sitecore adds the validator item’s ID to the Suppressed Validation Rules field defined in the standard template. As a result, validation of ALL fields in this template to which this field validator is assigned is suppressed. Since the “Is Required” field validator might be used on other fields in the inheriting templates, not just the fields in the Thumbnail Listing base template, I now have a created a separate unique field validator, “Thumbnail Is Required” for suppressing validation on only the base template’s fields. I also changed the new validator’s Title field to “Thumbnail Listing Is Required."



I then assigned this new field validator item to the Validator Button and Validator Bar for the two “Thumbnail Listing” fields.



The Thumbnail Listing fields are now required in the Standard Values for the Home Page and all other page templates that inherit it. However, you might remember that the fields are not required on the Non-Topic Section Listing template. Following the instructions from this blog post from John West: I right-clicked on one of the red squares that is using the “Thumbnail Is Required” field validator in the Standard Values of the Non-Topic Section Listing template and selected “Suppress Validation Rule."



This added the Thumbnail Listing Required field validator item’s ID to the Suppressed Validation Rules at the bottom of the Validation section.  As a result, all fields in this template to which this field validator is assigned – in this case, the Thumbnail Title field and the Thumbnail Listing field – will not be required. However, any fields that may have the “Is Required” field validator assigned will still be shown as required.



This technique is not the only way to tackle the challenge of requiring values for fields in base templates, and suppressing that validation in one or more inheriting templates, but it is easy to implement for any of Sitecore’s standard field validators or your own existing custom field validators.


Latest Ideas

Take advantage of our expertise with your next project.