Load page with specific data isset

Hello,

Perhaps it’s allready solved, I don’t really found…
I want to make two links for the same template that will change the array of the snippet inside.
I wrote the projects.html like that :

<?php snippet('header') ?>

  <main id="expositions" class="main" role="main">

    <header>
      <h1><?= $page->title()->html() ?></h1>
    </header>

    <section class="wrap">
      <div class="intro text">
        <?= $page->text()->kirbytext() ?>
      </div>
      <?php snippet('showcase', array('category' => myCategory)) ?>
    </section>

  </main>

<?php snippet('footer') ?>

And then, in my snippet I wrote that :

<?php if(isset($data)) $category = $category->limit($data);
      $expositions = page('expositions')->children()->visible();
      $expositions = $expositions->filterBy('category', $category);
      ?>

<ul class="showcase grid gutter-1">
<?php foreach($expositions as $exposition): ?>

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

<?php endforeach ?>
</ul> 

Now, I wan’t to make two links with something like a data-attribute that can change the myCategory data, is it really possible ?

I don’t really understand your code.

What is myCategory in the template, that is neither a variable nor a string, but I suppose you want to pass a $categoryvariable (a collection of pages?, a parameter from the URL?) to the snippet.

What is $data, where does that variable come from (nowhere defined), but from the code I’d suppose it is a number.

But then you want to filter your exposition by category, but your category is defined as some sort of collection, so that code doesn’t really make sense.

The myCatergory will be a category of an exposition.

For the moment, when I replace it by 'permanent' or 'non-permanent' (for example) the data change and the page load only 'permanent' expositions or 'non-permanent' expositions in the page , it runs when I do it.

But now I want to load directly the page with the data set. I was thinking about get an attribut in the link to load the exposition page with that attribut instead of myCategory

I don’t know if it’s clear…

Aha, ok, you want to sent a category as parameter via your URL. That is of course possible, e.g. a URL like this

https://mydomain.com/exhibitions/category: some-category

The you can fetch the category using the param() helper

$expositions = page('expositions')->children()->visible();
if($param = param('category')) {
  $expositions = $expositions->filterby('category', $param);
}
  

But then this code would be better of in the template or in a controller, and you pass the $expositions variable down to the snippet.

 <?php snippet('showcase', array('expositions' => $expositions)) ?>

Your snippet would then start with the list and the foreach loop.

You still haven’t explained what $data in your snippet is; if it is not an integer, why do you use it with the limit()method that expects an integer?

<?php if(isset($data)) $category = $category->limit($data); // data must be an integer here, otherwise this doesn't make sense; the limit method doesn't make sense if $category is a string

And if $category is just a category, then calling limit()on it doesn’t make any sense anyway, because for that to work, you would need some sort of collection.

Thank you ! It runs very well… I wanted to make it more complicated that it was.

I used the $data and the limit() for an old code… My bad, I wanted to go fast