Get images for slider from specific folder

Hey everybody,

I’m trying to make my own small portfolio with kirby. For the moment everything works really good, except one issue with my slider.

I have my slider images in a separate folder called “slider” and something with my code seems to be wrong. I only know php a little bit, so I#m not sure about what is wrong. I already tried some different variations of this snippet, with brackets and with etc. but I didn’t get it working for 2 days, so I thought I have to ask the experts.

Here is my code in the static HTML:

<div class="slider">
  <ul class="rslides" id="home-slider">
    <li><a href="#"><img src="slider/image1.jpg" alt=""></a></li>
    <li><a href="#"><img src="slider/image2.jpg" alt=""></a></li>
    <li><a href="#"><img src="slider/image3.jpg" alt=""></a></li>
  </ul>
</div> 

And here is my latest try how to get it working (imageLink is a meta-information given by me…)

<div class="slider">
  <ul class="rslides" id="home-slider">
    <?php foreach(page('slider')->images() as $image): ?>
      <li><a href="<?php echo $image->imageLink(); ?>"><img src="<?php echo $image->url() ?>" alt=""></a></li>
    <?php endforeach ?>
  </ul>
</div>

Any suggestions what is wrong in my for loop?

Thank you very much :slightly_smiling:

What is the output you get? Any error messages? Where is the slider folder located?

Also, the method $image->imageLink() does not exist by default. Does that come from your image meta file in your case?

So it seems …

1 Like

Why don´t you use $image->url().

I have made a snippet for the bootstrap carousel. Maybe it helps to take a look at this file
https://github.com/jbeyerstedt/kirby-site-snippets/blob/master/plg-carousel.php

He does for the image source.

Sorry, i only saw the first part of that code line

But I also don’t understand, what he wants to achieve with imageLink() and why the url of the image is not enough to link to the image.

I guess, the image is supposed to link to something else, maybe a website project but let’s wait and see …

Yes, I want to link to a specific project, that’s why I have this extra meta information… I happened, that I couldn’t see anything from the content under the slider. The slider folder is located in the normal content folder.

But I solved this issue 2 minutes ago. I just forgot to close the img-tag in the end. The snippet works perfect now :slight_smile: But thank you anyway! When you think about it for too long you oversee the basic mistakes -.-

<div class="slider">
  <ul class="rslides" id="home-slider">
    <?php foreach(page('slider')->images() as $image): ?>
      <li><a href="<?php echo $image->imageLink(); ?>"><img src="<?php echo $image->url() ?>" alt=""/></a></li>
    <?php endforeach ?>
  </ul>
</div>

Do you use the HTML5 doctype? It shouldn’t make a difference there.

Hi.

I used the plc-carousel for my website, but it doesn’t work.
The site appeared only to the line I have used <?php snippet(‘plc-carousel’).

There is a folder “carousel” with images in my page where I want to use the slider.
And I added the constants to the config.php.

Has anybody an idea what I’m doing wrong?

Thank you so far.
Daniel

Looks like you have to pass some variables to the snippet call:

snippet('plg-carousel', array(
'currentPage'=>$page,
'preNormal'=>'optional html to add before carousel',
'preAlt'=>'html if snippet is not displayed (for other styles)'
))

preNormal and preAlt seem to be optional.

Ah! Yepp. That works. Thank you for your fast reply.

I’m a beginner with php and kirby.
Could you give me a little hint what’s the difference between $currentPage and $page in this case?

Thanks
Daniel

That’s just how the snippet is built, it’s specific to that snippet, not to Kirby. :slight_smile:

My snippet must know the page it has been called from to search for the carousel folder, so you pass the $page object to the snippet.
It’s common in kirby to pass all the arguments to a snippet in an array and currentPage is only the name of the argument, so that I can access the passed information in my snippet.

PS: I think, it would be better, if you had opened a new thread, because your question was not directly associated with this thread.
Or even better: simply write me an email or open an issue on the github page of the plugin directly.

Thanks for this explanation.

Daniel