Forum

Thread tagged as: Question

Extended Navigation when creating Perch pages

Hi,

I've got a "Services" page which currently contains 4 services. These 4 services each have a page, created in Perch. On this main services page I want to display the services as a list, with a link to click through. Using perch_pages_navigation, the data I can get from each page seems limited to the url, title and description fields etc.

Is there any way to access regions used on the individual services page? So each service page has a synopsis (Created using a region called Individual Service Synopsis) and an image (created using a region called Individual Service Images). Can I pull this synopsis and image in anyhow to the main "Services" page?

If not, am I better off going down the List Detail route for this?

Thank you.

Joe Proctor

Joe Proctor 0 points

  • 3 years ago
Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

You should be able to achieve this with perch_content_custom(): Using content from different pages

perch_content_custom('Services', [
    'page' => '/services/*'
]);

Hi Hussein, thanks for that, that has got me somewhere! But it's outputting all at once. I've iterated over them using

'each' => function($item) 

but am struggling to access this using a template as I can't reference the template in the each loop. I've gone back to basics, my code is below, so it's grabbing the content from the region:

<?php
perch_content_custom('Individual Service Synopsis', [
    'page' => '/services/*',
    'template' => 'services-nav.html'

]);
?>

Is there a way to spit the content from the region (Individual Service Synopsis), into the template using <perch:content> tags?

Thanks.

Duncan Revell

Duncan Revell 78 points
Registered Developer

Just to help with what you want to do, when you say "outputting all at once", is that not what you wanted? You want a one page list of data that lives on 4 other pages?

Or do you mean that all the content from each page is showing, as opposed to just the image and the synopsis?

Hi Duncan, basically I have 4 pages (created in Perch) that are each a service, I.e dog walking, dog sitting, dog feeding etc

Each page has a region called 'Individual Service Synopsis'. On the main services page (effectively the listing page) I want to display the synopsis for each service and then a link to that page underneath. Using perch_content_custom I can access the region but it spits all 4 synopsis' out at once.

If I use the "each" function I can loop through and show what I want to show (synopsis and link) but it involves echoing a lot of HTML in the each function. I'd rather get the HTML in a template and call the template in the each loop each time. It doesn't appear this is possible however?

Thanks.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You need to get the navigation using skip-template and then loop through those pages calling perch_content_custom() with the current page option for each.

Thanks Drew, that has got me what I need. I think what I was after isn't possible anyway. I was just hoping to keep the PHP a bit clean and let a template do the work. This is my code (before adding HTML to the foreach loop) in case it helps anyone else:

<?php
    $navigation = perch_pages_navigation(array(
        'from-path' => '/services/',
        'skip-template' => true,
    ));
?>

<?php 

    foreach($navigation as $nav_item) {

        echo $nav_item['pageTitle'];

        perch_content_custom('Individual Service Synopsis', [
            'page' => $nav_item['pagePath']  
        ]);

        echo $nav_item['pagePath'];
    }

?>