<?php
// Template name: Flexible Template
?>

<?php get_header(); ?>

	<main id="content">

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

			<?php if ( have_rows('blocks') ) : ?>

				<?php while ( have_rows('blocks') ) : the_row(); ?>

					<?php
						$block = get_row_layout();
						$block = str_replace('_', '-', $block);
						$file = get_template_directory() . '/blocks/' . $block . '.php';
					?>

					<?php if ( file_exists($file) ) : ?>

						<?php include($file); ?>

					<?php endif; ?>

				<?php endwhile; ?>

			<?php endif; ?>

		<?php endwhile; ?>

	</main>

<?php get_footer();
