volume_up

A critical vulnerability was discovered in React Server Components (Next.js). Our systems remain protected but we advise to update packages to newest version. Learn More

volume_up

A critical vulnerability was discovered in React Server Components (Next.js). Our systems remain protected but we advise to update packages to newest version. Learn More

Add page to ContentArea programmatically

Hi all,

How to add a new page (new block) in the ContentArea programmatically? I want to implement this in method "public override void SetDefaultValues(ContentType contentType){}" when the object initializing.

Thanks for your help

#74012
Aug 17, 2013 8:38

I am not sure what you mean with new page? From a content area you can only reference existing pages. Todo so you could have override SetDefaultValues in your model class and do something like:

public override void SetDefaultValues(ContentType contentType)
{
     base.SetDefaultValues(contentType);
     MainContentArea = new ContentArea();
     MainContentArea.Add(ServiceLocator.Current.GetInstance<IContentLoader>().Get<StartPage>(ContentReference.StartPage));
}

#74022
Aug 19, 2013 8:32
Ted

Note that the Add method is obsolete as of EPiServer 7.5, which means you need to add a ContentAreaItem to the ContentArea's Items property instead.

#81107
Feb 10, 2014 13:51
error This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.