1

I'm new to EPiServer so you might find my question very simple. Please help!

Question: Where can I insert the code that programmatically creates a child page to the newly created EPiServer page?

Context: When an editor goes to the Edit View of the EPiServer Website and creates a new page, the system as expected creates an instance of the page type selected. However, I also want the system to create a child page to this newly created page based on custom code.

I've seen heaps of examples on how to programmatically create a page, but I have not seen samples of where to insert this code.

Let's say I have a Cars Classification Page Type. When an editor manually creates an instance of this via EPiServer, I want the system to go to the DB, get all the different classifications, and creates a child page for each of the classifications under the newly created Cars Classification Page Type (ie. Sedan Page, Hatchback Page, Sports Page).

Nicola
  • 851
  • 7
  • 11

2 Answers2

0

Ok so I found a solution to my problem. It's a combo of creating a custom attribute that can be attached to page types and a class that inherits IInitializableModule (EPiServer.Framework) which intercepts page creation and checks if the created page has the mentioned new attribute. If it does, then call the method that creates sub pages.

Found a very useful post here. However, the code is from 2011 so some of the classes no longer exist (EPiServer Framework 6R2 vs my 8.0) so I had to update them. But the gist is there. For those interested to see my code, hit me up!

EDIT: Here's how I solved it - https://blog.nicolaayan.com/2015/03/episerver-auto-create-child-pages-on-add-new-page/

Nicola
  • 851
  • 7
  • 11
  • Started a new blog with the solution to this as my first post! http://nicolaayan.blogspot.com – Nicola Mar 08 '15 at 04:18
0

In short you could create an InitializableModule in which you hook up to the PageCreated event of the ContentRepository to create a page underneath the newly created page.

Sort of like the following: http://tedgustaf.com/blog/2010/5/attach-episerver-event-handlers-on-startup-using-initializablemodule/

Note: in EPiServer 7/8 you would use ServiceLocator.Current.GetInstance<IContentRepository>() instead of DataFactory when attaching your event handlers and programmatically editing content.

Edit: nevermind, just realized you had found Anders' post on the subject. :) Good luck!

Ted Nyberg
  • 7,001
  • 7
  • 41
  • 72