Set the standard values based on condition

Viewed 42

I have 2 items: "Collection" and "Category". Both of them use the same template A which has field IsCollapse. When I create any new collection it should have the default value of true and for category it should have false. I cannot create a separate template for each of them as the website has lots of business data for both items. Is there any way other than writing custom code to have some kind of rule in Sitecore to set different values for the same field?

1 Answers

If you were to built this functionality from scratch, I would recommend creating a base template with the field IsCollapse. Templates Collection and Category would inherit from the base template and each template would have its own __Standard Values and the default value for IsCollapse field.

This is the ideal solution, however, as you already have a template and a lot of existing data and business logic around it, it is possible to use Branch Templates to achieve similar results.

You can create two separate branch templates based on the same Template A: Collection and Category. Each branch template will have its own $name item where you can specify default values for the IsCollapse field:

Branch templates

Then you can configure insert options to use branch templates Collection and Category instead of corresponding data templates: Insert options dialogue

Related