Article text and images not displayed


#1

I’ve typed an article for my news page—entered content and put in some pictures—but for some reason no text appears and only one image is loaded.

This is my article and this is my template. This is my blueprint.

Here are some screenshots of the panel: 1, 2, and a screenshot of the site itself.

I’m currently serving the site locally, with MAMP. What could cause the mysterious disappearance of the article images and text?


#2

If your text file is called article.txt and you want it to be rendered with its own template, the template has to have the same name, i.e. article.php, not homepage_article.php (otherwise, the default template is used).


#3

D’oh, always the simplest things that trip me up! Thank you!


#4

Actually, if I could just bother you once more if you don’t mind. I’ve restructured the site a little bit so it makes more sense, but still not all of the images are appearing.

You can see a live version of the site at http://davl.berghuijs.design. The first news post has several images, but only the first is loaded.

I am loading the images like this:

<? if($article->images()): 
    $images = $article->images(); 
    $firstimage = $images->sortBy('sort', 'asc')->first(); ?>
    <a href="<?= $firstimage->url(); ?>" data-caption="<?= $firstimage->alt()->html(); ?>" class="article-image-link first">
        <figure class="homepage-article-image">
            <?= $firstimage->thumb(array('width' => 600)); ?>
        </figure>
    </a>
    <?php foreach($images as $key => $image): 
        if($key > 1):?>
    <a href="<?= $image->url(); ?>" class="hidden" data-caption="<?= $image->alt()->html(); ?>">
        <figure class="">
            <?= $image->thumb(array('width' => 1)); ?>
        </figure>
    </a>
        <?php endif; ?>
    <?php endforeach; ?>
<? elseif($article->image()): 

I’ve put up my templates and snippets in this gist.

What could be the reason that only the first image is loaded? I suspect it has something to do with the snippet of code above.


#5

The problem is that the $key is not a numerical value what you expect. It is actually the filename.

So this part will fail.

        if($key > 1):?>
    <a href="<?= $image->url(); ?>" class="hidden" data-caption="<?= $image->alt()->html(); ?>">
        <figure class="">
            <?= $image->thumb(array('width' => 1)); ?>
        </figure>
    </a>
        <?php endif; ?>

You can do it like this.

    <?php foreach($images->not($firstimage) as $image): 
    <a href="<?= $image->url(); ?>" class="hidden" data-caption="<?= $image->alt()->html(); ?>">
        <figure class="">
            <?= $image->thumb(array('width' => 1)); ?>
        </figure>
    </a>
    <?php endforeach; ?>

#6

Thanks so much! This solved my issue.