Forum

Thread tagged as: Question

How do I display just the title from each region on a page?

I have a page made up of several regions. How do I display a section navigation at the top of the page to link to the title of each region? i.e:

<div id="section-nav">
  <a href="#Region1Title">Region1</a> |  <a href="#Region2Title">Region2</a> | <a href="#Region3Title">Region3</a>
</div>
Mike Harrison

Mike Harrison 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Since regions aren't dynamic, you'd just add your navigation by hand.

If you are generating regions dynamically with your own PHP, then you'd use the same logic to generate the navigation.

What about extracting an item from each region such as:

<perch:content id="SectionHeading" type="text" title="true" />

Could I do this from multiple regions, using perch_content_custom?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes you can, but you'll need to add the regions to the perch_content_custom() call by hand.

How do I go about that? Sorry to keep asking questions but I have only just started learning the Perch lingo and finding perch_content_custom difficult to grasp.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ah, sorry! I was thinking you were a different Mike Harrison.

If you want to aggregate content form multiple regions on the same page, it might be that the page structure needs rethinking. But that aside, you should be able to do it like so:

perch_content_custom(['Region A', 'Region B', 'Region C', 'and so on'], [
    'template' => 'section_heading',
]);

Your section_heading.html template would then include the common field from your regions:

<perch:content id="SectionHeading" type="text" title="true" />

No worries Drew - I really need to change my name to something more unique! The code works great except that it pulls the headings from the regions in a strange order see below for example:

Region C - Section 1, Region B - Section 1, Region A - Section 1, Region C - Section 2, Region C - Section 3

Is there a way I can use perch_content_custom to sort by region first, and then by heading?

Thanks, Mike.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You can't actually sort by region, no. Pulling content from multiple regions is the sort of thing we allow for, but the system was never really designed to work that way.

The thinking is that if you've put the regions in the page, you already know what they are.