Forum
PHP If Statement
Hi,
I wanted to drop in a simple PHP if statement to check if a region had content or not and then if so, to output the HTML, however it's only outputting the contents of the region and none of the HTML. Can you help?!
<?php if(perch_content('H2')!='') : ?>
<div class="row">
<div class="col-sm-12">
<h2 class="title-lg"><span><?php perch_content('H2') ?></span></h2>
</div>
</div> <!-- / .row -->
<?php endif; ?>
Try
Great, worked a treat Robert, thank you!
Sorry, I was too quick, it's just spitting everything out now, regardless of whether perch_content('H2', true) is actually true or not. Any further suggestions are welcome.
Why not do this in the template?
https://docs.grabaperch.com/docs/templates/conditionals/if/
is returning:
Have you added data to the region named "h2".
Hi Robert, you've hit the nail on the head. The region didn't actually exist within the content therefore the conditional statement was irrelevant. I went in and saved the region with null content and it's working as expected now. So
Is the correct conditional for what I wanted it to do. I did think about moving it into a template and using the alternative method you mentioned...that's a learning curve for another day!
Great, glad it's all working now. I'm headed off the grid now. Lol. :)