Conditionally display modal containing

Hi there,

I am using a jquery modal to display messages spit out by:

<?php echo flash(); ?>

This all works fine. However, because the modal initializes on page load, I would only like it to fire IF there is a message to display. So, my thought was to wrap the whole thing in a conditional statement, like the following:

<?php if flash(): ?>
  <div class="modal">
    <?php echo flash(); ?>
  </div>
<?php endif; ?>

However, this particular code does not work. Does anyone have any ideas? As a sidenote, does this approach even seem sound? Thanks in advance!

You can assign the flash() output to a variable then test that and print the variable if the test succeeds, so you don't have to call flash twice:

<?php
$flash = flash();
if ($flash):
?>
<div class="modal">
    <?php echo $flash; ?>
</div>
<?php endif; ?>

Hi John,

This solution worked perfectly. Many thanks for you assistance and apologies for the delayed response. All my best!