Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Inline blocks inside ContentArea do not have a unique id, they are part of the page.
Hi Arjan,
Inline blocks do not inherit IContent which would give you the ability to use your above code. They are stored in a property bag.
However that doesn't mean you can't get a unique id.
The method I would alternatively use is a custom content area render.
The custom content area render would give you a list of each of the items in the content area. I can only presume each inline block has its own property bag with a unique identifier otherwise how is this done in the admin screen.
Once you have the unique id from the property bag you can append this to the block that is rendered.
This is untested, so take this with some caution.
Paul
Not sure if this work but I guess there is need for a unique identifier for the inline block, for instance if used within an IList<Blocktype> property and add block to them programaticlly. You should be able to create something like this, if below is not working perhaps you need to use contentrepository.getdefault and then you will also need to cast the block to IContent and set a unique name before you save them.
var page = contentRepository.Get<MyPage>(pageReference);
// Create your block inline
var block1 = new MyBlock
{
Title = "First Block",
Content = new XhtmlString("<p>This is the first block's content.</p>")
};
var block2 = new MyBlock
{
Title = "Second Block",
Content = new XhtmlString("<p>This is the second block's content.</p>")
};
page.Blocks = new List<MyBlock> { block1, block2 };
contentRepository.Save(page, SaveAction.Publish, AccessLevel.NoAccess);
With the new inline blocks, how would we find a unique id for it? Something like:
or ContentLink.ID will fail because these blocks are not IContent instances.
It's not like I can't generate something myselft, but it's a problem with existing code where this is used to output unique identifers in HTML..