New to Kirby - How do I edit the showcase snippet to fit my own site structure?

My site uses this structure in place of “projects”:

home/artworks/artwork1
home/artworks/artwork2
etc

I naively assumed I could replace “project” and “projects” string in the showcase snippet but this breaks the page and throws up an error. I have templates in place for artworks and artwork, which worked until I inserted my edited code.

The reason I need to do this is I need to categorize my portfolio at the top level, instead of having everything lumped into one.

<?php
$projects = page('artworks')->children()->visible();

/*

The $limit parameter can be passed to this snippet to
display only a specified amount of projects:


<?php snippet('showcase', ['limit' => 3]) ?>


Learn more about snippets and parameters at:
https://getkirby.com/docs/templates/snippets
*/



if(isset($limit)) $artworks = $artworks->limit($limit);

?>

<ul class="showcase grid gutter-1">

  <?php foreach($artworks as $artwork): ?>

    <li class="showcase-item column">
        <a href="<?= $project->url() ?>" class="showcase-link">
          <?php if($image = $artwork->images()->sortBy('sort', 'asc')->first()): $thumb = $image->crop(600, 600); ?>
            <img src="<?= $thumb->url() ?>" alt="Thumbnail for <?= $artwork->title()->html() ?>" class="showcase-image" />
          <?php endif ?>
          <div class="showcase-caption">
            <h3 class="showcase-title"><?= $artwork->title()->html() ?></h3>
          </div>
        </a>
    </li>

  <?php endforeach ?>

Whats the error?

Also if you are using page() function https://getkirby.com/docs/cheatsheet/helpers/page then you need to specify whole URI.

It seems like you should put it page(‘home/artworks’) if your folder structure is as you say (home/artworks).

And the second problem: you define $projects but then use $artworks in the loop:

<?php
$artworks = page('home/artworks')->children()->visible();
if(isset($limit)) $artworks = $artworks->limit($limit);

?>

<ul class="showcase grid gutter-1">

  <?php foreach($artworks as $artwork): ?>

    <li class="showcase-item column">
        <a href="<?= $artwork->url() ?>" class="showcase-link">
          <?php if($image = $artwork->images()->sortBy('sort', 'asc')->first()): $thumb = $image->crop(600, 600); ?>
            <img src="<?= $thumb->url() ?>" alt="Thumbnail for <?= $artwork->title()->html() ?>" class="showcase-image" />
          <?php endif ?>
          <div class="showcase-caption">
            <h3 class="showcase-title"><?= $artwork->title()->html() ?></h3>
          </div>
        </a>
    </li>

  <?php endforeach ?>

Thanks. I fixed that mistake - page no longer broken. But now there’s no image displayed at all

Are there any images in the artwork1 etc folders?

Yes, there’s images in there. They’re displayed fine on pages using my artwork template. However, nothing is rendered after the “artworks php” on my artworks page:

to clarify, all my PHP is inside the “grid” div

Could you please do a dump after the first line

<?php
$artworks = page('home/artworks')->children()->visible();
dump($artworks);

if(isset($limit)) $artworks = $artworks->limit($limit);

?>

I get this rendered on the page when I do that:

Children Object
(
)

Hm, looks as if the page home/artworks does not have any children. Is this some sort of misunderstanding regarding the structure, maybe?

The current code assumes that you have a subpage “artworks” in the home folder, and each artwork is a folder within the artworks parent folder.

Currently I have one artwork folder while I work on the site:

home/artworks/artwork

Within the artwork folder I’ve got the text file and some images

Is the artwork folder visible (i.e. does it have a prepended number): 1_artwork1? If not, either make it visible, or remove the visible() method:

$artworks = page('home/artworks')->children();

That worked, thanks!