Hi Akito, You could traverse up the tree until you find a page of pagetype (BlogHome)... by traverse I mean get parent in a recursive function. Another way would be to add a reference to blog from PostX when it is created, you can attach to the created event and check if the page type created is the one your looking for, then do the traverse and save the reference to blog in a property.
Any other suggestions community?
Don't know if there is a standard way of doing it but what I find myself doing and often see in other solutions is to but some properties as settings for the site on the startpage because episerver gives a static getter to the startpage reference. I also often find myself adding a startpage property to my baseclass for my pages.
So I would suggest something like this:
///
/// Base class for all page types
///
public abstract class BasePageData : PageData
{
///
/// Returns the Start page
///
public StartPage StartPage
{
get
{
return DataFactory.Instance.Get(ContentReference.StartPage);
}
}
....
///
/// Page definition for Start page
///
public class StartPage : BasePageData
{
///
/// Reference to News container page
///
[Display(Order = 200, GroupName = SystemTabNames.Settings)]
public virtual PageReference NewsContainerPage { get; set; }
.......
var blogChildren = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance().GetChildren(StartPage.NewsContainerPage);
Thanks Jacob and Petter for your input.
We ended up adding a BlogListing PageReference (parent of all blog posts) to the StartPage/HomePage and then referencing that in the APIController:
var homePage = DataFactory.Instance.Get
IEnumerable
Not sure if that would be best practice but it works. If I can find a better way to accomplisg this I will post it.
Thanks again!
Akito
HI,
This is my first attempt at a EpiServer site and I'm trying to figure out how to get the children of a particular page. I'm using EpiServer 7.5 with MVC. I'm creating an API controller that returns x number of blog posts with an offset of y. In EpiServer the currentPage is based on context. The Controller Action will determine exactly what the current page is. But what happens if you want to create that context by saying give me all children of the page tree node called "blog"? How do I get the node called "blog"? I've tried to use PageReference.ParseUrl("/blog") but this doesn't work. I can't use the GetPage function:
DataFactory.Instance.GetPage(new PageReference(10))
because the ID may be different in each environment. Is there a standard way of doing this in EpiServer?
Thank you.
Akito
Root
Home
Blog
Post1
Post2
Post3
...