I recently spotted the code for a wp-lunch.php
file intended for a WordPress template, what would this look like if following the proper WordPress coding standards?

<?php if ( current_user_can('has_sandwich') ): ?>
<?php get_sandwich_header(); ?>
<?php while( has_filling() ): the_filling(); ?>
<?php get_sandwich_part( 'thick_layer',
get_filling() ); ?>
<?php endwhile; ?>
<?php get_sandwich_footer(); ?>
<?php endif; ?>
What happen if the user don’t have capability to eat sandwich? WSOF?
If I’d want to follow average default themes templates, I’d go for
// eat-sandwich.php (as @Rarst said avoid wp-lunch.php as it's not part of WP core)
get_header( 'sandwich' );
if ( current_user_can( 'eat_sandwich' ) ) {
get_template_part( 'eat-sandwich', 'content' );
} else { // user can't eat sandwich. An apple?
$alternative = apply_filters( 'alternative_to_sandwich', 'apple' );
if ( 'sandwich' == $alternative ) {
// No sandwich allowed!
$alternative="apple";
}
get_template_part( "eat-$alternative", 'content' );
}
get_footer( 'sandwich' );
And then
// eat-sandwich-content.php
$fillings = get_fillings_query(); // in functions.php
if ( $fillings->have_posts() ) : while ( $fillings->have_posts() ) :
get_template_part( 'filling', get_filling_type() );
endwhile;
wp_reset_postdata();
else :
_e( 'Sorry, no fillings found. Eating an apple may help to stop hunger.', 'txtdomain');
endif;