The context
I have the following code:
<ul>
<?php foreach($users as $user){ ?>
<li>
<?php echo $user->name ?>
</li>
<?php } ?>
</ul>
It renders:
<ul>
</ul>
When there are $users
, everything works well. However, when there aren't, the <ul>
is rendered with blank spaces in it, making it not attributable with the CSS selector :empty
.
I managed to solve the problem by doing this:
<ul><?php foreach($users as $user){ ?>
<li>
<?php echo $user->name ?>
</li>
<?php } ?></ul>
It renders:
<ul></ul>
Without the like breaks in the code, the list is now empty (even empty of blank spaces), but I'm afraid to leave it that way and some other programmer fix the indentation and break it.
My question
Is there a way to add line breaks to the code without adding blank spaces or breaks to the rendered html element?