Developer forum

Forum » Development » Retrieving child pages with template available API? JavaScript alternative?

Retrieving child pages with template available API? JavaScript alternative?

Tobias Næss
Reply

Hi,

 

I'm making a visual representation of a menu structure for a new project - regrettably it's locked down behind VPN right now so I can't link to it.

Basically I have a navigational structure where each of the child pages has a custom paragraph type with an image and some other attributes that I'd like to fetch programmatically. Ideally I would like to get these values server-side via some kind of template or navigation loop.

The structure looks like this

  • -Parent page
  • -- Child page
  • ---- Paragraph with custom field "image", "owner", "type"
  • -- Child page n
  • ---- Paragraph with custom field "image", "owner", "type"

What I want to achieve/optimize is getting the paragraph data if I know the parent page ID.

What I'm doing now is this:

  1. I have a custom navigation that takes the parent ID and outputs links to the child pages in the DOM
  2. The child page links are fetched in an array with JavaScript
  3. Via jQuery.load I'm getting the content from the DOM of the child pages and inserting the response into the DOM of the page I'm in

The JavaScript looks like this:

$menu = $(".menu a");
start = Date.now();
v = 0;
$menu.each(function(){
  var $this = $(this);
  var url = $this.attr("href");
  var img = $("<div>").load(url+"?LayoutTemplate=Designs/DOFGroup/vesselsnav.html #carousel-image", function(response, status, xhr){
    if(status == "success"){
      var $img = $(img).find("img");
      var type = $img.data("type");
      var owner = $img.data("owner");
      var name = $img.attr("alt");
      $("<p>").html(name).appendTo(img);
      $("<span>").addClass("type").html(type).appendTo(img);
      $("<span>").addClass("owner").html(owner).appendTo(img);
      $(img).attr("data-owner",owner).attr("data-type",type).attr("data-owner",owner).attr("data-name",name).appendTo("#content-heading");
      v++;
      var vtime = Date.now();
      diff = (vtime-start)/1000;
      console.log("Vessel "+v+" in total "+diff+" seconds.");
    }
    });
});

As you can see there's some debugging data in there. I load the pages using a minimal template. However it's still hugely inefficient - loading all the data can potentially take up to 20 seconds, and it's a lot of unnecessary HTTP requests.

 

I know using eCom or even News modules would make more sense in this particular scenario, but we're stuck with using basic pages/paragraphs, regrettably.

Using the functionality available in the templates or in the navigation - is it possible for me to extract this data in another way?

 

 

 

 


Replies

 
Tobias Næss
Reply

After some deliberation this setup changed a bit, and we copied the images to the MenuGraphic setting, so that the page load now is much faster. The question still remains though - having access to sub-page content via navigation or otherwise, without needing to render the page - that would be great to have some kind of input on.

 
Nicolai Høeg Pedersen
Reply

Without fully understanding what you want to achieve, could it be possible you just need the XML of the navigation from an http request?

 

You can do that by using /admin/public/GetNavigationXML.aspx. You can configure it from management center, designer node.

 

BR Nicolai

 

You must be logged in to post in the forum