Shared Region in a template Block

  • I have several shared regions eg. price table, reviews, brand logos etc and need to be able to display them in different places within a page. My pages are setup using blocks so you can reorder and add different blocks of content. Is there a way to have a block template which has checkboxes in so the editor can check to display reviews or price table. Doing this inside blocks gives the flexibility to specify where these blocks of content (shared regions) appear on the page.

    I've read this thread but not sure I understand or it's doing quite what I want:

    Can I use a Shared Region in a template Block

    Page template has a multiple item region with block templates to choose from and add content too:

    1. <?php perch_content('Page sections'); ?>

    Page sections template:

    test_var.html block template with checkboxes:

    I have the following code working on the page template but not sure how to get it displaying via the checkbox within the blocks template?

    This code displays only the html from the desired shared region:

    I've also tried testing it outside of any blocks just by a normal perch region, but this doesn't output anything:

    1. <h3>Variable test should appear here: <?php perch_content('Variable Test'); ?></h3>

    Template for the the 'Variable Test' region I'm using has this code:

    1. <perch:content id="sharedregion_data" html>

    I feel so close!… Any help would be greatly appreciated.

  • drewm

    Approved the thread.
  • With fresh eyes I've now got it working! Hopefully this post will be useful to others, below is what I did to get working:

    Updated template:

    1. <perch:if exists="Reviews">
    2. <!*-- Checking this box load reviews from the Reviews Shared Region *-->
    3. <!*-- Perch if - Only display if the box is checked *-->
    4. <!*-- Suppress checkbox so it doesn't output to page *-->
    5. <perch:content id="Reviews" type="checkbox" label="Show Reviews" suppress>
    6. <!--* added type hidden the field doesn't show in the Admin *-->
    7. <perch:content id="sharedregion_data" type="hidden" html>
    8. </perch:if>

    On the Page template I changed perch_content to perch_content_custom as I realised the template needs to process as the page loads.

    I've also tested within Blocks and reordered the items to move the content to the desired area of the page. So this now means I can have the content in one editable place 'Shared Regions' adding them to a page in any order.

    I've added more variables to the Page template and added more checkboxes to the blocks template, making sure the set_var name is different for each one.

    And updated the blocks template: