Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Removing else; what to do with if?

I would like to remove the else statement in the following code.

How shall I convert the if statement, so it still works (route is correct/ logo is being shown)?

<div class="logo a">
        <a href="<?=$site_url;?>">
            <?php if(isset($settings['site_logo_image']) && $settings['site_logo_image'] != '') { ?>
                <img src="<?=$site_url;?>_img/logo.png" class="image_logo" border="0" height="40" alt="<?=(isset($settings['site_logo']) ? $settings['site_logo'] : 'Hello');?>" />
            <?php } else { ?>
                        <?=(isset($settings['site_logo']) ? $settings['site_logo'] : 'Hello');?>
            <?php } ?>
        </a>
</div>

If I leave out the if prefix, it’s not working.
I am not a pro in php and actually have to do with frontend stuff…

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thanks

>Solution :

It’s a bit tricky to read php interspersed with HTML. Once you get the knack of it, though, it’s straightforward. Delete everything from else { to the next }. Like this.

<div class="logo a">
  <a href="<?=$site_url;?>">
    <?php if(isset($settings['site_logo_image']) && $settings['site_logo_image'] != '') { ?>
      <img src="<?=$site_url;?>_img/logo.png" class="image_logo" border="0" height="40" alt="<?=(isset($settings['site_logo']) ? $settings['site_logo'] : 'Hello');?>" />
    <?php }  ?>
  </a>
</div>

Pro tip A language-aware IDE like VSCODE or PhpStorm will alert you immediately if you make a mistake doing this sort of thing.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading