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:
- I have a custom navigation that takes the parent ID and outputs links to the child pages in the DOM
- The child page links are fetched in an array with JavaScript
- 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?