Forum

Thread tagged as: Question

Using content from perch_content_custom on a page by page basis

Hello!

I wonder if you could help me - it's probably me not being very good, but hopefully someone has an answer.

I am getting content from multiple regions on a page, i.e.

perch_content_custom(
  array(
    'Artist Name',
    'Artist Images'
  ), 
  array(
    'page'=>'/artists/*',
    'template' => '_artist_list.html'
  )
);

But when the data comes out, it loops through the data displaying the data for Artist Name in _artist_list.html, then Artist Images in _artist_list.html and so on.

How can I group the content returned to a template per page basis, so for the first page it would output both regions from page1.php into _article_list.html, then both regions from page 2 into _artist_page.html

I guess it might be by I need to use the callback (each) function - to group page items together and then return a new array item with the data from each page?

Hope that's clear enough - if not, I'll explain further anyway I can.

Matt Bee

Matt Bee 0 points

  • 6 years ago
Matt Bee

Matt Bee 0 points
Registered Developer

I've managed using what I think is a bit hacky, but given fields will always exist it should be OK;

<perch:if exists="text">
<li>
    <a href="<perch:content id="_page" />">

</perch:if>

<perch:if exists="artist_images">
   <perch:repeater id="artist_images" label="Artist Images">
      <perch:if exists="perch_item_first">
          <img src="<perch:content type="image" id="image" label="Image" width="248" height="248" />" alt="<perch:content type="text" id="alt" label="Description of the image." />" />
      </perch:if>
    </perch:repeater>
</perch:if>

<perch:if exists="text">

    <div class="hover"><h2><perch:content type="text" id="text" /></h2></div>
</perch:if>

<perch:if exists="artist_images">
  </a>
</li>

</perch:if>

Not sure if that was the best solution though - an example of how I could merge data in the each function would be great ;)

Thanks,

Matt

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, you could merge data using an each callback, or if you're using Runway just create a relationship.

But what you're doing will also work. It's always a bit dicy selecting from multiple regions - I added that feature while muttering under my breath that I shouldn't ;)

Matt Bee

Matt Bee 0 points
Registered Developer

Thanks Drew,

I thought that it was a bit dicy, as you say. I think I might refacter it to loop through the pages and create the html and data in the page itself, using navigation and then just getting the data from the multiple regions as I need it.

Cheers! Keep up the good work!