Forum

Thread tagged as: Question

Sharing content between multiple regions

I have a system using multiple regions to create a timeline style list of content.

  • Each region created represents a point on the timeline.
  • All parts on the timeline are displayed on the same page (hence the multiple regions).
  • Each point in the timeline links to the next point via an anchor.

Few questions:

  • Is it possible to check if a region is followed by another region?
  • Is it possible to 'add 1' to perch_item_index?
  • Is it possible to use content from the next region? e.g. Use it's title within a link.

Essentially what I'm looking to do is create a link at the end of every point linking to the next point using it's region title and ID.

Tony Astley

Tony Astley 0 points

  • 3 years ago

Do you mean multiple items within a single region? You might find this useful: https://docs.grabaperch.com/perch/content/functions/how-do-i-link-prev-next/

Hello Shane,

That's not quite what I'looking for, plus link to the list and detail demo it refers to is broken. I've worked around it by structuring the loop differently.

If anyone is interested I used the following method utilising perch_item_first & perch_item_last:

<perch:if id="perch_item_first" value="false">
        <a href="#stage<perch:content id="perch_item_index" type="hidden"/>" class="nextStage" title="Next Stage: <perch:content type="text" id="stageTitle" label="Stage Title" title="true" />">Next Stage: <perch:content type="text" id="stageTitle" label="Stage Title" title="true" /></a>
        </div><!--/.stage-->
</perch:if>

    <div class="stage" id="stage<perch:content id="perch_item_index" type="hidden"/>" data-aos="fade-up">

        <h3><perch:content id="perch_item_index" type="hidden" />. <perch:content type="text" id="stageTitle" label="Stage Title" /></h3>

        <perch:content type="textarea" id="StageDescription" label="Stage Description" html="true" editor="ckeditor" /> 

<perch:if exists="perch_item_last">                     
    </div><!--/.stage-->
</perch:if>

First of all I check to see is perch_item_first is set to false. If it is not I know that the item is not first in the list and I can show what essentially is the top of the next stage.

The middle section of the template is pretty standard Perch Stuff.

The perch_item_last if statement checks if the item is last in the region, and if so shows only the closing tag for the block element.

The <perch:showall /> is very useful for finding attributes you can manipulate.


2 of the 3 original questions still stand though:

  • Is it possible to 'add 1' to perch_item_index?
  • Is it possible to use content from the next region? e.g. Use it's title within a link.

As this approach would not work for some blocks of code where links to the next section would be situated in the middle of the block.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Is it possible to 'add 1' to perch_item_index?

Yes, you can do that with a template filter.

Is it possible to use content from the next region?

What do you mean by next region here? Regions aren't sequential.

Hello Drew,

My terminology is not quite right, let me try to clarify. I have a multiple item region with each item stacked on top of the other, with anchors links moving the user down the page. What I want is to include content from the next item. Each item has:

  • Item Title
  • Item Content
  • Link to Next item

It's the link to next item that caused me an issue. I want to link to the next items id="perch_item_index", and within that link include the next items title.

I read the page about template filters and that's not what I need. I need to do this within the HTML template as the links exists within the item.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You might be best to skip-template and loop through manually.

Thanks Drew,

I've worked around this one using a different structure to the template. If the situation arises again I'll probable give it a try.

As long as I know it's not possible I can stop searching/tinkering/cursing :-)