Adding a second gallery (in the boilerplate)

Hey -
I would like to add a second projects page (with the title “publications”) to my site.
But somehow the content stored as project sites (stored in the “publications” site folder) is not displayed but the ones from the default projects site. I tried to replace the showcase-snippet with a copy where instead of $projects I use $publications, but it is not working.

I can’t wrap my head around where I am linking the wrong things.

Any clues?
Thank you!

This line in the showcase.php snippet fetches the projects:

$projects = page('projects')->children()->visible();

As you can see, it gets the children of page('projects') so you would have to make a copy of that snippet and call page('publications') instead. Or remove that line completely, and page the correct page to the snippet. On my way out now, so I can’t post the code. Maybe someone else will in the meantime, otherwise I will come back to this later tonight.

Dear texnixe,

thanks again for your support, I’ve tried it bu it didn’t work out so far somehow. Here is the “publications” snippet I created.

<?php

$think = page('think')->children()->visible();

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

?>

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

  <?php foreach($think as $project): ?>

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

  <?php endforeach ?>

</ul>

The page is called “think” and I’ve created a copy of the projects-template for it.
There is clearly some kind of mistake in my logic of linking template, page and snippet, maybe you wil see it imidiately.

Best,
Laura

Why do you keep deleting the code? Do not post code as quotes! I have now edited it three times to make it appear as a code block.

Sorry, we clearly disrupted each others editing… I was just getting back because I saw the code did not turn out teh way I wanted it…

Code blocks need to be wrapped within three backticks (```) on a separate line before and after a code block. See my edit.

But: What exactly is the problem? Or rather what is the result as compared to your expected result?

The result is the following error message:

This page is currently offline due to an unexpected error. We are very sorry for the inconvenience and will fix it as soon as possible.

As a very first important counter measure to finding errors without groping in the dark, please enable debugging in your config file

c::set('debug', true);

Edit: In your foreach loop, you use $think instead of $project several times which does not make sense! $think is a collection of pages and does not have a title.

<?php

$think = page('think')->children()->visible();

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

?>

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

  <?php foreach($think as $project): ?>

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

  <?php endforeach ?>

</ul>

Thanks for being so quick and helpfull! I should have installed the debugger in the first place - I followed the instructions and found the two $project i turned into $think, which totally makes no sense. Now it works, thank you!

1 Like

I think if you choose more speaking names for your variables, you are less likely to run into such problems. If something is a collection, I usually use a plural ($projects) or a name that makes clear that something consists of more than one item (e.g. $collection). $think, however, sounds more as if it was only one thing.

You are right - the choose of think was linked to the menu title of the page, which does not need to be the variables name. Classic logic mistake…