Forum

Thread tagged as: Problem

Retrieving content from multiple regions

I'm having difficulties grabbing content from multiple regions and getting it to display properly.

I have a number of pages under /jobs/ and I'm trying to create an overview page at /jobs/index.php which links to all the subpages and includes the page title, an image and a description.

Each page under /jobs/ has the following regions:

Hero image, Blurb, Content

I'm trying to grab and output the field 'image' from Hero image and the field 'text' from Blurb.

Here's my code:

<?php
            perch_content_custom(['Hero image', 'Blurb'], [
                'page' => '/jobs/*',
                'template' => 'listings.html',
                'count' => 4,
            ]);
?>

And my listings.html template:

    <div class="wrapper wrapper--small">

        <div class="grid">

            <div class="grid4">
                <a href="<perch:content id="_page" replace=".php|" />">
                <img src="<perch:content id="image" />" class="" alt="" width="700" height="300">
                </a>
            </div>

            <div class="grid8">
                <perch:content id="text" />
            </div>

        </div>

</div>

All the content is coming out but the HTML is output twice - one block has the image and no text and the other has the text and no image. So some sort of looping issue?

Stephen Turvey

Stephen Turvey 0 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Your image tag is missing the type attribute. It's required.

I've added type, thanks. That hasn't fixed my problem, though.

Drew McLellan

Drew McLellan 2638 points
Perch Support

What problem are you seeing?

All the content is coming out but the HTML is output twice - one block has the image and no text and the other has the text and no image. So some sort of looping issue?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ah, I see. I think you might be going about this backwards. Take a look and see if this helps: https://docs.grabaperch.com/perch/content/functions/how-do-i-create-list-detail-pages/

Although the approach you suggest makes sense I am coming in and building this overview page on a site that already has all the subpages live on the web so I'm looking for a way to work with what's already there rather than start from scratch, if that makes sense? I have minimal budget available to me unfortunately!

Drew McLellan

Drew McLellan 2638 points
Perch Support

If the content has been split into multiple regions, then you're going to have to get the data back and reintegrate it using PHP.

Ok thanks Drew. Just one question while on the topic of perch_content_custom: in the template I can use <perch:content id="_page" /> to get the page URL... what would I need to get the page title?

Drew McLellan

Drew McLellan 2638 points
Perch Support

The page title isn't available.