Show attributes only when filled (with a if statement?) 5.6

Permalink
Hi, Is it possible to display some html output only when the attribute is filled? Let's say a Facebook event button that only shows on the page if there is a link filled in the probities of the page with a attribute called 'facebook_event'? So something like this

<?php if ($facebook_event): ?>
   <a class="bttn" href="<?php echo $facebook_event ?>" target="_blank">Check this event</a>
   <?php endif; ?>


How can I set it so it will check of the attribute is filled or isn't blank?

 
hutman replied on at Permalink Reply
hutman
You could do

<?php 
$facebook_event = $c->getAttribute('facebook_event');
if ($facebook_event && strlen(trim($facebook_event)) > 0):
   ?>
      <a class="bttn" href="<?php echo $facebook_event ?>" target="_blank">Check this event</a>
<?php endif; ?>