Forum

Thread tagged as: Question

PHP perch_content with echo

I'm putting a popup on a website which I've allowed the client to active and deactivate.

Template for reference:

<perch:content id="popupactive" type="radio" label="Activate Popup?" options="Yes, No" suppress="true" />
<perch:if id="popupactive" value="Yes">
<div class="subscribe-me">
    <a href="#close" class="sb-close-btn">x</a>
    <perch:content id="body" type="textarea" label="Body" markdown="true" editor="markitup" required="true" />
</div>

</perch:if>

Then in the page I only want to show the region and it's related js and css files if that's activated. I'm half way there with the below. The 'Popup' regions markup display only when it's activated but the echo of the js and css files displays regardless.

<?php
 if (perch_content('Popup', true)) { 
perch_content('Popup');

echo'<script src="/js/jquery.subscribe-better.js"></script><link rel="stylesheet" href="/css/subscribe-better.css">';

} ?>

Sarah Evans

Sarah Evans 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

$popup = perch_content_custom('Popup', [
    'skip-template' => true,
    'return-html' => true,
]);

if ($popup[0]['popupactive'] == 'Yes') {
    echo $popup['html'];
    ...
}