Indenting/code organization with HTML+PHP mixed together

Indenting/code organization with HTML+PHP mixed together

ek1

Member
Local time
14:32
Joined
Oct 6, 2019
Messages
81
Pronouns
She/her

Working on a wordpress project right now and I keep running into situations like this:

HTML:
<header>Hello!</header>

<?php while (have_posts()) : the_post(); ?>

<div class="post-wrap">
    <h3 class="title"> <?php the_title();?> </h3>
    <div class="post">
        <?php the_content();?>
    </div>
</div>

<?php endwhile;?>

My instinct is to indent the current-post-wrap <div> block because it's inside a PHP while statement - even though it's on the same level as the <header> block...!

Is there a standard way to do this? I guess you could argue it's not a huge deal as long as you standardize it throughout the project but I'm curious.

 
Last edited:

Gummibeer

Astroneer
Moderator
Local time
18:32
Joined
Oct 5, 2019
Messages
1,169
Pronouns
he/him

The times I worked with WordPress I indented the inner of a loop.

 

Adam

Mr. Webwide
Administrator
Local time
17:32
Joined
Sep 24, 2019
Messages
1,257
Pronouns
he/him

I’ll vote indent no matter what, so html inside PHP on a new level regardless of the actual HTML structure. I used to care about how the HTML source looked once compiled and might have worked around that but I guess nobody cares about that any more since most sites are a scary mess of divs and generated class names behind view-source.

 
Last edited:
Top