I have one small issue with my code below, I'd like the HTML view of the source code to be "tidy" as well as the PHP, I've spent days searching but I've drawn a blank as to why the HTML side is not tidy, the only thing I'm guessing is extra whitespace is being generated, if that's the case I'm not sure why, if anyone could help it would be appreciated, thanks.
html
<div class='col-md-12'>
<div class='alert alert- info'>
Already Logged In
</div>
</div>
php
<div class='col-md-12'>
<?php if ($action=='logged-in'): ?>
<div class='alert alert- info'>
Already Logged In
</div>
<?php endif ?>
</div>
Your lines with just PHP code still keep their whitespace, so the spaces at the beginning of that line and the at the end still count.
Unfortunately, this means you'd have to have your code look like this:
<div class='col-md-12'>
<?php if ($action=='logged-in'): ?> <div class='alert alert- info'>
Already Logged In
</div>
<?php endif ?></div>
Pretty ugly, right?
You have a couple options:
Since it looks like the root <div>
will be there no matter what, try using the following:
echo
'<div class="col-md-12">',
($action == 'logged-in' ? '
<div class="alert alert-info">
Already Logged In
</div>' : '
'), '
</div>';
Fiddle: Live Demo