自定义短文版Kirby CMS php

I have a home page with short versions of the articles which link to the article page [(from this tutorial)][1]

        <?php foreach($page->children()->visible()->flip() as $article): ?>

                    <h1 class="posttitle_home" itemprop="headline">
                        <a href="<?php echo $article->url() ?>" rel="bookmark"><?php echo html($article->title()) ?></a>
                    </h1>
                    <div class="postcontent_home" itemprop="articleBody">
                        <p><?php echo excerpt($article->text(), 300) ?></p>
                    </div>
                    <time class="date_home" datetime="" itemprop="datePublished"><?php echo $article->date('d/m/Y') ?></time>
                    <a href="<?php echo $article->url() ?>" class="readmore_home">Read More</a>
                </article>

            <?php endforeach ?>

        <?php endforeach ?>

This works fine, but I want short versions of the custom post types (from this tutorial) I add if statements to use different h1 tags depending on the template used for the article like this:

<?php foreach($page->children()->visible()->flip() as $article): ?>

        <?php foreach($articles as $article): ?>

            <?php if($article->template() == 'article.tutorial'): ?>

            <article class="article_home tutorial" role="article" itemscope itemtype="http://schema.org/Article">

            <?php elseif($article->template() == 'article.freebie'): ?>

            <article class="article_home freebies" role="article" itemscope itemtype="http://schema.org/Article">

            <?php elseif($article->template() == 'article.review'): ?>

            <article class="article_home review" role="article" itemscope itemtype="http://schema.org/Article">

            <?php endif ?>

                <h1 class="posttitle_home" itemprop="headline">
                    <a href="<?php echo $article->url() ?>" rel="bookmark"><?php echo html($article->title()) ?></a>
                </h1>
                <div class="postcontent_home" itemprop="articleBody">
                    <p><?php echo excerpt($article->text(), 300) ?></p>
                </div>
                <time class="date_home" datetime="" itemprop="datePublished"><?php echo $article->date('d/m/Y') ?></time>
                <a href="<?php echo $article->url() ?>" class="readmore_home">Read More</a>
            </article>

        <?php endforeach ?>

    <?php endforeach ?>

I get an error and the page doesn't work. I'm a php noob so any help would be amazing. Thanks

I solved the issue by removing the inner foreach

 foreach
   <?php foreach($articles as $article): ?>
     if
     elseif
     endif
   <?php endforeach ?>
 endforeach