Treelists are great controls for letting the editors point out a list of items.
For eksample when choosing which spots to show in a spot column. But when you have a lot of different spots and not all of them fits into the spot column populated by the field, you want to make sure that editors don't choose the wrong spots.
The best thing would be that editors didn't even have the possibility to select the wrong spots in the treelist.
Scenario
The scenario is the following.
We have three different spottypes in the website. All the spots is placed in a global folder named ”Spots”. In this folder each spot type has its own folder, with the possibility to add more folders of the same type.
On the website we have a spot column to the right. This column is not wide enough to contain a link spot. And we don't want the editor to add a link spot to this column by mistake.
We could solve this issue by writing code that made sure that spots of the wrong type is not shown in this column. But it turns out that this approach is not necessary.
By using the source property of the RightSpots field, we can make sure that the editor never chooses spots of the wrong type.
Setting the source property
The source property is set on the template
There are several way to do this. In the following I will describe a couple of them.
As we do not want to allow editors to add link spots to this field, the editor should only be able to choose items of type NewsSpot and TextSpot. They should of course not be able to select item of type NewsSpotFolder or TextSpotFolder.
So we insert the following datasource into the source property.
Datasource=/sitecore/content/Spots
&IncludeTemplatesForDisplay=TextSpotFolder,TextSpot,NewsSpotFolder,NewsSpot
&IncludeTemplatesForSelection=NewsSpot,TextSpot
The treelist now looks like the following picture.
It is only possible to select items of type NewsSpot and TextSpot. That means that the editor can not select a spot folder by accident.
It would also be possible to do this the other way around by excluding templates instead of including them.
In that case the property would look like this.
Datasource=/sitecore/content/Spots
&ExcludeTemplatesForDisplay=LinkSpotFolder
&IncludeTemplatesForSelection=NewsSpot,TextSpot
Please observe that we still need to include IncludeTemplatesForSelection to disable the editor from choosing spot folders.
The list of parameters are
- DataSource
- DatabaseName
- IncludeTemplatesForSelection
- ExcludeTemplatesForSelection
- IncludeTemplatesForDisplay
- ExcludeTemplatesForDisplay
- IncludeItemsForDisplay
- ExcludeItemsForDisplay
- AllowMultipleSelection