Forum
Multiple Regions in perch_content_custom()
Is it possible to pull in content from multiple regions using perch_content_custom?
I have a set of pages with regions called "logo" and "opening hours". I'd like to output the content of those regions from each of those pages into a set of blocks on another page.
Yes, you can pass an array of region names in.
Awesome. All working apart from the Opening Hours is a multi-item region (not a repeater, d'oh). How do I get it to pull in more than one item?
Pulls in just the first set of hours
Pulls in every shop's hours in one bulk
From what I can see, by putting
it is outputting the two regions separately
What output do you get? I don't know how your data is structured, so I'm working blind.
Some example data exported vie <perch:showall />
Ok, so that looks like 3 items from
opening-hours
and one fromlogo
.What were you expecting?
Kind of. But the whole list seems to come through in a bit of an erratic order. I get the logo then one of the hours, then the rest of the hours corresponding to that shop will be much further down the list
What I was kind of after, was the logo and hours to be grouped together per "shop page". As my desired effect was to create a panel with the shop logo and their opening hours for each shop, all on one page.
Ok - how are you ordering them?
I'm guessing I need a field that is common to both regions, so would "_pageID" work?
Nope, "_pageID" doesn't work. showall spits out nothing
It needs to be common to both but also put them in the correct order.
I have added the alt field to the opening hours region. I have also converted the opening hours region to include a repeater. I am now sorting the data by 'alt'
This is an example is the data I get now
Whilst the template displayed above is now getting all the data it needs, it is creating two code block. One that has the logo and no hours, and one that has the hours and no logo
It's like it is making two passes through the template, one for each region.
Excuse the rather messy PHP code (it's not my first skill). I cracked it via the raw data method.