November Happy Hour will be moved to Thursday December 5th.
AI OnAI Off
November Happy Hour will be moved to Thursday December 5th.
var rep = ServiceLocator.Current.GetInstance();
var newBlock = rep.GetDefault();
newBlock.YouProp = "Cool stuff";
rep.Save((IContent)newBlock, SaveAction.Publish)
writableClonePage.ContentArea.Items.Add(newBlock)
Just writing from memory here so could be a bug or two in there. But something like it. =)
Thanks Petter. But it seems ContentArea.Items.Add() expects a ContentAreaItem object?
clone.MainContentArea.Items.Add(new ContentAreaItem()
{
ContentLink = myReference
});
There is a forum post with similar code that you could use: http://world.episerver.com/Modules/Forum/Pages/Thread.aspx?id=86474
Thanks a bunch!
Here's what I ended up with:
var writableClonePage = (LandingPage)CurrentPage.CreateWritableClone();
var rep = ServiceLocator.Current.GetInstance();
var newBlock = rep.GetDefault(ContentReference.GlobalBlockFolder);
newBlock.ButtonLink = "http://www.episerver.no";
newBlock.ButtonText = "My button text";
IContent icontentBlock = (IContent)newBlock;
icontentBlock.Name = "Some name";
var savedReference = rep.Save(icontentBlock, SaveAction.Publish, AccessLevel.NoAccess);
var myContentAreaItem = new ContentAreaItem();
myContentAreaItem.ContentLink = savedReference;
writableClonePage.MainContentArea.Items.Add(myContentAreaItem);
rep.Save(writableClonePage, SaveAction.Publish, AccessLevel.NoAccess);
NP.
In case you would rather use the "for this page" folder, you could simply add:
var contentAssetHelper = ServiceLocator.Current.GetInstance();
ContentAssetFolder folder = contentAssetHelper.GetOrCreateAssetFolder(myPage.ContentLink);
var newBlock = contentRepository.GetDefault(folder.ContentLink);
Is it possible to programmatically add blocks to a page?
I would assume that you would have to to something like this