Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
AI OnAI Off
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Hi Glenn Adrian,
You should create instance like this instead:
var blockPropertyFactory = ServiceLocator.Current.GetInstance<IBlockPropertyFactory>();
var block1 = blockPropertyFactory.Create<SimpleLinkBlock>();
block1.ButtonText = "Simple Link Button 1";
block1.Heading = "Heading Test 1";
block1.Target = ContentReference.StartPage;
var block2 = blockPropertyFactory.Create<SimpleLinkBlock>();
block2.ButtonText = "Simple Link Button 2";
block2.Heading = "Heading Test 2";
TestBlocks = new List<SimpleLinkBlock> { block1, block2 };
Reference: List Properties (optimizely.com)
Version: 12.25.1
Block is a simple link block with a heading, text and PageReference for target.
We have content that has an IList property of this link block and we would like the property to be created with a couple of links setup by default. We use SetDefaultValues to create a list with a few link blocks setup (using some example values here):
public override void SetDefaultValues(ContentType contentType) { base.SetDefaultValues(contentType); AccordionItems = new List<SimpleLinkBlock> { new SimpleLinkBlock { ButtonText = "Simple Link Button 1", Heading = "Heading Test 1", Target = ContentReference.StartPage }, new SimpleLinkBlock { ButtonText = "Simple Link Button 2", Heading = "Heading Test 2", } }; }
The result when creating a new instance of the Content is a list of 2 SimpleLinkBlock's that are completely empty. The values we set does not get copied.
Is there a workaround that does not involve moving SimpleLinkBlock away from being a block and creating descriptors?