Hide if none exists

Permalink
I have a page property called "sub_header" that I display if it is set on a page. If it is not set, I use the page description.

How can I suppress the <h2> wrapper code if neither the "sub_header" or description is set?

Here is my code
<h2><?php
         $attr = $c->getAttribute('sub_header');
         if (empty($attr)) {
            echo $c->getCollectionDescription();
         }
         if (isset($attr)) {
           echo "$attr";
         }
         ?></h2>

mattarnzen
 

This website stores cookies on your computer. These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media. To find out more about the cookies we use, see our Privacy Policy.