SaaS CMS has officially launched! Learn more now.

How to create a custom property in a content type that contains nested properties?

Vote:
 

We are trying to create a generic custom property to render out a checkbox with a normal Optimizely built in property. This is an idea of what we would like to achieve:

[Display(Name = "My Custom Compound field", GroupName = CustomTabNames.Others, Order = 370)]
public virtual CustomCompoundField<decimal> CustomCompoundField { get; set; }
public class CustomCompoundField<T>
{
    [Display(Name = "My boolean", GroupName = SystemTabNames.Content, Order = 1)]
    [CultureSpecific]
    public virtual bool MyBoolean { get; set; }

    [Display(Name = "My property")]
    public virtual T MyProperty { get; set; }
}

Also, If it's feasable, how would we be able to render it on the  Optimizely admin UI?

Any help is appreciated.

#325239
Jul 11, 2024 14:42
Vote:
 

Hi Taher

It's possible, but not common. Optimizely CMS has supplied many built-in property types that covers majority of the use case, you can find more details from Built-in property types (optimizely.com)

Back to your scenario, if you want a property renders checkbox in CMS, you can use decoreate your property with SelectOne Or SelectMany attribute Single or multiple list options (optimizely.com)

I hope this helps.

#325276
Jul 12, 2024 6:12
Vote:
 

You could go for a block property. Here you define a block with your properties, and then you make a property with the block as the type.

To hide the block type anywhere else, you will then decorate its class with 

[ContentType(AvailableInEditMode = false)]
#325291
Jul 12, 2024 15:19
Taher.elhares - Jul 14, 2024 7:34
The problem with this approach is that we will have over 40 of these returned from one type and it will cause performance issues when content is returned from the content delivery api.
Stefan Holm Olsen - Jul 14, 2024 9:44
If you contain them all in a single block property, then it will not be worse than having them directly on the page type.
Stefan Holm Olsen - Jul 14, 2024 9:45
In which scenario do you need 40 compound properties? Maybe there is an alternative solution.
Taher.elhares - Jul 15, 2024 10:42
Regarding my scenario we have properties in our variant that we need to know if they are a hero attributes or not based on a Boolean property to display them on a product page.
* 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.