Developer forum

Forum » Templates » Get pages that are children of a given parentpage using the API

Get pages that are children of a given parentpage using the API

Hans Ravnsfjall
Hans Ravnsfjall
Reply

Hi

I am trying to get at list of active pages that are children of a given parentpage using the API

Guess what i have to use is this https://doc.dynamicweb.com/api-docs#article=91fd0116-1d77-a43b-83e0-ed140ebb478b

So far i have tried a lot of things, but canĀ“t get it to work. Can anyone guide me in the right direction?

What I have so far is:

@{
 string parentpagestring=@GetString("DwPageID_1");
 int parentpage=Int32.Parse(@parentpagestring);
 IEnumerable<Page> mytree=Dynamicweb.Content.IPageService.GetPagesByParentID(@parentpage);
 }

 

But this just gives an error

have also tried

@{
 string parentpagestring=@GetString("DwPageID_1");
 int parentpage=Int32.Parse(@parentpagestring);
 var mytree=Dynamicweb.Content.IPageService.GetPagesByParentID(@parentpage);
 }

 

Anyone who can guide me in to getting some sort of "thingy" that I can loop through the pages under a given ParentPageID? (Sorry for my terminology)?

 

/Hans


Replies

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply
This post has been marked as an answer

Hi Hans,

 

I believe you are using the wrong namespace and class. Try this instead

 var mytree=Dynamicweb.Services.Pages.GetPagesByParentID(parentpage);

and you can make your life easier if you do this

var parentpagestring=GetInteger("DwPageID_1");

That will get you an integer so you don't have to parse it

 

Best Regards,

Nuno Aguiar

Votes for this answer: 1
 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Hi Nuno

thank you very mutch. I think I got it to work by using this

 

@{
 var parentpage=@GetInteger("DwPageID_1");
 PageService P = new PageService();
 var mytree=P.GetPagesByParentID(@parentpage);
 }

But how can i "Loop" through the pages, and get these attributes for each of the pages in "mytree"?

https://doc.dynamicweb.com/api-docs#article=bfda3aa5-0cb4-37c5-6304-331fe41a782a

 

/Hans

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply
This post has been marked as an answer

Hi Hans,

 

As such

@{
 var parentpage=@GetInteger("DwPageID_1");
 PageService P = new PageService();
 var mytree=P.GetPagesByParentID(@parentpage);

  foreach (var page in mytree) {
    //page is each page within that tree
    <h2>@page.MenuText</h2>
  }
 }

 

Best Regards,

Nuno Aguiar

Votes for this answer: 1
 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

So simple :)

perfect, thank you Nuno :)

 

/Hans

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply
This post has been marked as an answer

You are welcome

Votes for this answer: 1

 

You must be logged in to post in the forum