Problem retrieving content from multiple regions

  • /shared.php has multiple regions each one has a unique template/IDs. I've used IDs from two regions, and added them to cta--box.html.


    I was hoping to output the `IDs` from multiple regions into one template, but it's not working as expected.



    This is my setup

    Code
    1. perch_content_custom(['name', 'phone'], [
    2. 'page'=>'/shared.php',
    3. 'template'=>'_global/cta--box.html',
    4. ]);


    _global/cta--box.html

    Code
    1. <div class="contact-details">
    2. NAME: <perch:content id="name" type="text"></br>
    3. PHONE: <perch:content id="phone" type="text">
    4. </div>



    Source/output looks like this:


    Code
    1. <div class="contact-details">
    2. NAME: Janet Wilson</br>
    3. PHONE: <!-- missing phone? -->
    4. </div>
    5. <div class="contact-details">
    6. NAME: <!-- missing name? --></br>
    7. PHONE: 0123 456 7890
    8. </div>


    It's like perch_content_custom is handling each region separately, and then applying the template to each region. If I add more regions to perch_content_custom the number of times the template is repeated is the same.


    I've tried using count => 1 with perch_content_custom that stops the repeating problem, but doesn't fix the missing content?



    What's the best way to approach this?





    Summary information


  • drewm

    Approved the thread.
  • Perch is sourcing all the items from the regions specified and then filtering and sorting them as one big set before templating. So what you're seeing makes sense.


    If the name and phone number belong together, why not put them as a single item in the same region?

  • Quote

    The example shown is a bare bones version of a bigger template, I'd rather not combine into one region if possible.

    Ok, that's fine, but just as long as you're aware you're fighting against the system rather than working with it.


    Is there a way to pull the content out of perch_content_custom before it's output to the page, and then use the IDs in another template?

    Yes, you can use the skip-template option to return the content to the page before it's output.