Creating If/Else in WordPress

I’m trying to create an if/else. The idea is that if there is a right widget assigned to the page, then display the widget and content like this:

content goes here
right widget goes here

else only display this:

content goes here

I’m trying to work this out by using this:

    <?php 
            if(is_active_sidebar('right-column')){
                echo '<main id="main" class="site-main" role="main">';
while ( have_posts() ) : the_post();
get_template_part( 'content', 'page' );
if ( comments_open() || '0' != get_comments_number() ) :
                        comments_template();
                    endif;
endwhile;
echo '</main>';
                echo '<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">';
                dynamic_sidebar('right-column');
                echo '</div>';
                } else {
                echo '<main id="main" class="site-main" role="main">';
while ( have_posts() ) : the_post();
get_template_part( 'content', 'page' );
if ( comments_open() || '0' != get_comments_number() ) :
                        comments_template();
                    endif;
endwhile;
echo '</main>';
}
            ?>

What’s happening is that I’m encountering a PHP error (blank page), so obviously I’m missing something in the code. Anyone have an idea where I’m missing something?

See if you get any error message when you have your debugging turned on. Go to your wp-config.php file and change

define('WP_DEBUG', false);

to

define('WP_DEBUG', true);

Just remember to change it back to false before the site goes live.

Thanks, WebMachine. I was able to modify the code to something like this:

<?php 
            if(is_active_sidebar('right-column')){
                echo '<main id="main" class="site-main col-lg-8 col-md-8 col-sm-6 col-xs-12" role="main">';
                while ( have_posts() ) : the_post();
                get_template_part( 'content', 'page' );
                endwhile;
                echo '</main>';
                echo '<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">';
                dynamic_sidebar('right-column');
                echo '</div>';
                } else {
                echo '<main id="main" class="site-main" role="main">';
                while ( have_posts() ) : the_post();
                get_template_part( 'content', 'page' );
                endwhile;
                echo '</main>';    
                }
            ?>

It seems to have worked when I ran a few tests.