Developer forum

Forum » Templates » Navigation between child pages (previous / next case)

Navigation between child pages (previous / next case)

Emil Klindt Sørensen
Reply

Hello there,

I've been encouraged to write my question here on the forum, and hoping that someone has previous experience with this or something similar.

We're looking for a way to navigate forward and backwards between client cases. The element would contain forward / backward buttons, the index of the current case/page and the total amount of cases/pages. The pages are all child elements of an overview page, which led me to the idea of getting all child pages of the top page, but unfortunately I was not able to do this by simply looking through the documentation.

Therefore I hoped that someone would point me in the direction of a better (or possible solution). One solution would be to manually map the cases, and manually state which case is the previous and next. Due to the amount of cases, this is not a desirable option. 

The element in question would look something like the attached file, where you can navigate between the pages. To give a better understanding of how the project is structured, I'll give an example of the content structure:

  • Homepage
  • Cases
    • Case 1
    • Case 2
    • Case 3
    • Case 4
    • ...
  • ...

Does anyone have an idea how to solve this problem, or previous experience with something similar?

Skærmbillede_2018-08-28_kl._09.43.47.png

Replies

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Emil

You have 2 options:

  1. You can create a navigation where you have an xslt that chooses the next (if present) and previous (if present). Using settings like this for your dwnavigation tag:
    startlevel:2;endlevel:2;expandmode:all;sitemap:nextPrevious.xslt;parentid:{idOfYourCasesPage}
    (Alternative to parentid: setting use parenttag:{NavigationTagOnCasesParentPage} - see manual here: https://doc.dynamicweb.com/documentation-9/content/content/pages#3241 and here: https://doc.dynamicweb.com/template-tags/introduction/concept/navigation#3442)
  2. In Razor, you can use the pageservice to find the page you are currently visiting and based on that, find the next and previous from there - something like this:
     

int currentPageId = Dynamicweb.Frontend.PageView.Current().ID;Dynamicweb.Content.Page currentPage = Dynamicweb.Services.Pages.GetPage(currentPageId);
int previousPageId = 0;
int nextPageId = 0;
int tempPageId = 0;

foreach (Dynamicweb.Content.Page page in Dynamicweb.Services.Pages.GetPagesByParentID(currentPage.ParentPageId))
{
    if (previousPageId > 0)
    {
        nextPageId = page.ID;
        break;
    }
    if (page.ID == currentPageId)
    {
        previousPageId = tempPageId;
    }
    tempPageId = page.ID;
}

if (nextPageId > 0) { }
if (previousPageId > 0) { }

Votes for this answer: 1
 
Emil Klindt Sørensen
Reply

That's a perfect solution to the problem, and exactly as desired. Thank you so much Nicolai!

The only thing that I will have to implement, is the index / total count. That should be quite straight forward though, since there's a look running through all the elements.

Thank you again!

 
Nicolai Pedersen
Reply

Hi Emil

Yes it should - you have the page collection of the parent - use the count to get all (remember to filter out inactive pages).

 

You must be logged in to post in the forum