One-pager technique to create slider/carosuel

As the title says, I’m would like to use the one pager to create something akin to slider of divs that horizontally scroll. I would like the each page to use the same snippet piece.php and for content to appear on the home page. Currently I’m getting the error “Call to a member function uid() on string”. How can I about fixing this?
Any help would be greatly appreciated.

home.php template

    $pieces = page('work')

<div id="wrapper">
    <?php snippet('nav') ?>
    <div class="content" data-page="<?= $page->uid() ?>">
        <div id="work">
            foreach($pieces->visible() as $section) {
                snippet($section->uid(), array('data' => $section));

piece.php snippet

<?php $num = 0; foreach($data->thumbnails()->yaml() as $image): $num++; ?>
    <?php if($image = $data->image($image)): ?>
        <div class="piece-cnt">
            <a href="<?= $data->url(); ?>" id="<?= $data->uid() ?>" num="<?= $num ?>" class="piece" data-slug="<?php echo str::slug($data->title())?>">
                <img src="<?php echo imgix($image, array('w' => 300)) ?>" />
    <?php endif ?>
<?php endforeach ?>

There is an error in your code, $pieces is not a collection you can loop through but a single page. Maybe you mean

$pieces = page('work')->children()->visible();


Also, you are trying to call the single snippet by the uid() of the page, which does not make sense if you always want to call the same snippet.

1 Like

don’t forget to take visible out of foreach($pieces->visible() as $section) if you try @texnixe suggestion