Calling all developers! We invite you to provide your input on Feature Experimentation by completing this brief survey.

 

Henrik Fransas
Oct 26, 2015
  8575
(2 votes)

The known and unknown of Include, IncludeOn, Exclude and ExcludeOn

These four settings have always been and are little headache for me and today I took some time trying to learn more about them.
Basically they work like this:

Include
A type array of typed content to specify which content types are available under a content instance of the type with the attribute.

Exclude            

A type array of typed content to specify which content types are not available under a content instance of the type with the attribute.

IncludeOn        

States that the content with this attribute is available under the typed content in the type array.

ExcludeOn       

States that the content with this attribute is not available under any of the typed content in the type array.

This is pretty straight forward and the most importing part is to realize that the Include is not just including the defined types, it is also excluding all other things.
But the funny/hard thing to learn is what happens when you combine them together, which property is more important than the other.

To figure that out I took a normal Alloy site and changed the settings for StartPage and ProductPage. 

[AvailableContentTypes(
        Availability.Specific,
        Include = new[] { typeof(SearchPage) }, 
        ExcludeOn = new[] { typeof(ProductPage) })] 
    public class StartPage : SitePageData
 [AvailableContentTypes( 
        Availability = Availability.Specific,
        Include = new[] { typeof(StartPage), typeof(SearchPage) },
        IncludeOn = new[] { typeof(StartPage) })]
    public class ProductPage : StandardPage, IHasRelatedContent

That gave me this look inside admin:

Image startpage1.png

Image productpage1.png

This shows me that IncludeOn and ExcludeOn are prioritized over Include and Exclude, since even though I say that I should include StartPage on ProductPage, it is not included and even though I do not define ProductPage to be included below StartPage it is included on it.

Then I wounded what would happen if I say that the only thing that should be able to be created below ProductPage should be StartPage and keep saying to StartPage that it should be ExcludedOn Productpage. So I changed the code for ProductPage so it looks like this:

    [AvailableContentTypes( 
        Availability = Availability.Specific,
        Include = new[] { typeof(StartPage) },
        IncludeOn = new[] { typeof(StartPage) })]
    public class ProductPage : StandardPage, IHasRelatedContent

I thought that I would end up not being able to create anything at all below ProductPage but to my surprise this is what the result was:

Image product2.png

Somehow I ended up with being able to create everything but StartPage and that was not I was hoping for and for me it feels like a bug, what does you think?

Oct 26, 2015

Comments

valdis
valdis Oct 26, 2015 10:10 PM

Sounds like a space to dig deeper :)

henriknystrom
henriknystrom Oct 27, 2015 12:20 AM

Had a quick look at this and would say that there is an issue here if the combined Include/IncludeOn and Exclude/ExcludeOn sets are matching up. The result will instead be the same as if only the exclude attributes were applied.

tss
tss Oct 28, 2015 12:01 PM

We figured out that if you use the Availability.Specific option you need to include at least one page in the Include clause

for the IncludeOn option to work for any sub pages you want to include on the page at a later point.

Hopefully this gets some love at some point, right now it is kind of confusing to use.

Henrik Fransas
Henrik Fransas Nov 17, 2015 08:28 AM

This is now fixed in EPiServer.CMS.Core 9.3.2

Jiri Cepelka
Jiri Cepelka Feb 7, 2018 06:42 PM

I’ve found discussion about related issue.

Why there is Availabilty property? 

I see there should be Include automatically excluding all others, Exclude automatically including all others, IncludeOn automatically excluding content type (CT) on all other CTs and ExcludeOn automatically including CT on all other CTs.

Why there is need to tell the attribute what is my intention specifically?

I think about properties like ExclusivelyIncluded, ExclusivelyExcluded, ExclusivelyIncludedOn, ExclusivelyExcludedOn.

The answer for question of prioritizing one over other in non-on and on ones strife lays in design intentions, i.e. to be able to overwrite class behavior without option to change it or not to be able to do that, I think so.

I found this quite a hodgepodge.

Please login to comment.
Latest blogs
Decimal numbers in Optimizely Graph

Storing prices as decimal numbers on a commerce website and planning to expose them through Optimizely Graph? It might not be as straightforward as...

Damian Smutek | Jan 23, 2025 | Syndicated blog

Find and delete non used media and blocks

On my new quest to play around with Blazor and MudBlazor I'm going back memory lane and porting some previously plugins. So this time up is my plug...

Per Nergård (MVP) | Jan 21, 2025

Optimizely Content Graph on mobile application

CG everywhere! I pull schema from our default index https://cg.optimizely.com/app/graphiql?auth=eBrGunULiC5TziTCtiOLEmov2LijBf30obh0KmhcBlyTktGZ in...

Cuong Nguyen Dinh | Jan 20, 2025

Image Analyzer with AI Assistant for Optimizely

The Smart Image Analyzer is a new feature in the Epicweb AI Assistant for Optimizely CMS that automates the management of image metadata, such as...

Luc Gosso (MVP) | Jan 16, 2025 | Syndicated blog

How to: create Decimal metafield with custom precision

If you are using catalog system, the way of creating metafields are easy – in fact, you can forget about “metafields”, all you should be using is t...

Quan Mai | Jan 16, 2025 | Syndicated blog

Level Up with Optimizely's Newly Relaunched Certifications!

We're thrilled to announce the relaunch of our Optimizely Certifications—designed to help partners, customers, and developers redefine what it mean...

Satata Satez | Jan 14, 2025