sczdavos
sczdavos

Reputation: 2063

PHP spaces in HTML output when formatting code

Following code will produce unwanted whitespace between icons.

<div>
    <img src="icon1.png" />
    <img src="icon2.png" />
</div>

I need to keep image tags on single lines because I have some conditions in my .phtml file, it looks something like this:

<div>
    <?php if ($condition1) : ?>
        <img src="icon1.png" />
    <?php endif ?>
    <?php if ($condition2) : ?>
        <img src="icon2.png" />
    <?php endif ?>
</div>

I don't want to have all code messed up on a single line. Is there any solution for situations like this?

Upvotes: 0

Views: 166

Answers (2)

max
max

Reputation: 2817

You may use echo to output parts of html code. You'll get something like this

<div>
    <?php if (true) : 
        echo '<img src="icon2.png" />';
    endif;

    if (true) : 
        echo '<img src="icon2.png" />';
    endif;
    ?>
</div>

Upvotes: 0

Engineer
Engineer

Reputation: 48793

Apply font-size:0px; style to your div.

Upvotes: 2

Related Questions