Forum

Thread tagged as: Question

Using a checkbox to display another region

I'm using a product details and list setup. At the end of each product page is a content panel (The Giving Back region). I want to be able to control if this Giving Back region appears via a checkbox in from the Products region (using the product-details.html template).

products.php

    <div class="section" id="product">
        <div class="inner">



            <?php
            perch_content_custom('Products', array(
                 'page' => '/the-shop/index.php',
                 'template' => 'product-detail.html',
                 'filter' => 'slug',
                 'match' => 'eq',
                 'value' => perch_get('s'),
                 'count' => 1,
            ));

            ?>
        </div>
    </div>

    <div class="section col-24">
        <div class="inner">

            <?php
            perch_content_custom('Giving Back', array(
                'filter' => 'giving_panel',
                'match' => 'eq',
                'value' => 'display',
            ));

            ?>

        </div>
    </div>

product-details.html

<perch:content id="giving_panel" type="checkbox" label="Display Giving back panel?" value="display"  suppress="true" />
Sarah Evans

Sarah Evans 0 points

  • 4 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

You will need to return the first region as an array with skip-template. That then won't output to the page, but if you pass in return-html you will also get the compiled html so you can echo that to the page. All the details of those options are in the docs:

https://docs.grabaperch.com/functions/content/perch-content-custom/

Then you can pick out the value you want to test against and use it in a variable in the second perch_content_custom function. That 'display' needs to be the variable you get from the first region.

Thanks for the reply.

I struggle with this stuff being more of a designer mindset than a developer, so I apologise in advance for not really getting it.

This is what I have now, I'm not sure how to echo it to the page?

    <div class="section" id="product">
        <div class="inner">

            <?php
            perch_content_custom('Products', array(
                 'page' => '/the-shop/index.php',
                 'template' => 'product-detail.html',
                 'filter' => 'slug',
                 'match' => 'eq',
                 'value' => perch_get('s'),
                 'count' => 1,
                 'skip-template' => 'true',
            'return-html' => 'true',
            ));

            ?>
        </div>
    </div>

    <div class="section col-24">
        <div class="inner">

            <?php
            perch_content_custom('Giving Back', array(
                'filter' => 'giving_panel',
                'match' => 'eq',
                'value' => 'display',
            ));

            ?>

        </div>
    </div>
Drew McLellan

Drew McLellan 2638 points
Perch Support

You need to catch the result into a variable that you can then use:

$products = perch_content_custom(...);

You can then output the result:

echo $products['html'];

and you can test for fields:

if ($products[0]['giving_panel']) {
    ... giving_panel is checked ...
}