Try our conversational search powered by Generative AI!

Adding new boolean that defaults to true


I have a lot of existing categories.

Now I want to add a new "VisibleInMenu" bool property to categories, and I want it to be checked by default i all the exisiting categories.

I have tried the SetDefaultValues approach, which did not work:

public override void SetDefaultValues(ContentType contentType)
VisibleInMenu = true;

I've tried overwrititng the get/set of the property, and that did not work:

[Display(Name = "Display in navigation", GroupName = SystemTabNames.PageHeader, Order = 1000)]
public virtual bool VisibleInMenu
return (bool)(this["VisibleInMenu"] ?? true);
this["VisibleInMenu"] = value;

Is this even possible without looping through all the categories and setting the value?

Jul 26, 2017 11:30

Unfortunately I don't think there is a way other than a migration. For these boolean cases (where I can't check for null somewhere in my code and use a default there) I sometimes revert the logic, if I find it semantic enough. But perhaps DontShowInMenu is not the best thing after all...

Jul 26, 2017 12:37

I would prefer if it could mimic the same semantics as the built in page, but I think I will have to go with a "HideInMenu" property instead.

Jul 26, 2017 12:39

Just make sure you use the SetDefaultValues to get the desired value for future creations of the content :)

Jul 26, 2017 12:41
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.