Forum
Check if Region exists
Hi Is it possible using PHP in a master page template to check if a Region exists and if not load another?
eg.
if(isset(Landing Page) {
$pageContent = perch_content_custom('Landing Page', $opts);
} else {
$pageContent = perch_content_custom('Subpage', $opts);
}
I know this is not correct syntax but wanted to give a better idea of what I am trying.
Thanks.
Thanks Drew
Can't quite get that to fit in with the way I'm displaying content sorry.
I am looping through navgroup assigned pages to show content on home page
Some pages have 'Landing Page' region and some 'Subpage' region.
Here is more of my code -
I echo out the content for each iteration of the loop.
Hope that explains.
Thanks
Ok, well it should be easy to adapt the principle to fit your page.
Hi Drew Thanks as always -
Got it working except getting I'm getting 'Undefined offset: 0 in.....' error message when loop first encounters the following line and the region 'Page' does not exist.
The error is displayed and then the isset($pageContent[0]['heading']) function works and the differently named region is used as wanted. In other words the page principle perfectly, using the 2 different pages that have different named regions but displays the error in the middle, I assume because the array is not returned by the perch content custom function?
Here is my code now with the error checking etc
Thanks again for the help.
This is really just a PHP question.
if (isset($pageContent[0]) && isset($pageContent[0]['heading']))
Thanks Drew. Of course, now I see it, it is obvious. Works like a dream, a beer I owe you! cheers