Issues with ajax load more

Hey, I went through the docs for Load More with Ajax but am having some issues getting it working

Currently the code is rendering all projects and then upon clicking ‘Load More’ is loading the last 2 project subpages a second time

Screen Shot 2021-06-05 at 12.19.28 pm

I have combed through the code a number of times to ensure it is the same but can’t work it out

Any suggestions?

Looks like you didn’t remove the part of the code that went into the project.php snippet from the projects.php template

Sorry which part should be removed?


<ul class="projects" data-page="<?= $pagination->nextPage() ?>">
  <?php foreach ($page->children()->listed() as $project): ?>
    <?php snippet('project', ['project' => $project]) ?>
  <?php endforeach ?>
<button class="load-more" accesskey="m">Load more</button>


<li class="">
  <a href="<?= $project->url() ?>">
    <?= $project->title()->html() ?>

No, that looks good. Could you please post all code snippets? Or maybe just provide a download link to the project via PM or a link to a GitHub repo, so that I can take a quick look where it is going wrong.

PM’d you!

Thanks, I overlooked the error above.

You need to use the $projects variable defined in the controller in the template:

So instead of

it needs to be

 <?php foreach ($projects as $project): ?>
1 Like

Thanks so much <3