Hello everyone,
I’m new to Kirby and stuck with this problem since a few hours now.
My question is how to get a video that is also nth(1) from a page folder?
nth() is a method you can use on a collection, however, your $videos variable (despite its deceiving plural form), is a single file. If you want to know if it is the first in the collection $page->files()->filterBy('type', 'video') use
<?php $videos = $page->videos(); // same as filterBy('type', 'video') ?>
<?php foreach ($videos as $video) : ?>
<?php if ($video->isFirst($videos) : ?>
<!-- do stuff -->
<?php endif ?>
<?php endforeach ?>
Please always post your code as text not as screenshots to allow for easy copy&paste.
Edit: What is the purpose of your if statement? If you only want to get the first video, you can use first() instead:
<?php if ($video = $page->videos()->first()): ?>
<!-- do stuff -->
<?php endif ?>
Could you please explain what you are trying to achieve in simple words? To me it looks as if all you want is a single video, hence no need for a foreach loop. If what I assume is true, you would have to use the second example of what I posted above after the Edit, without the loop.