I have a problem to put a logic in a controller

Hello,

I’m working on a home page and want to get actualities from an other page’s subpage.

It works just fine if I put the logic in the template like this :

templates/home.php :

<?php
$today = date('Ymd');
$actualites = $site->page('actualites')->children();

foreach($actualites as $actuality) {
    if($actuality->date('Ymd') < $today) {
        $pasts[] = $actuality;
    }
    if($actuality->date('Ymd') >= $today && $actuality->date('Ymd') <= $today + 7) {
        $presents[] = $actuality;
    }
    if($actuality->date('Ymd') > $today + 7) {
        $futures[] = $actuality;
    }
}
?>

But it does nothing if I put it inside the controller like this :

controllers/home.php :

<?php

return function($site, $pages, $page) {

    $today = date('Ymd');
    $actualites = $site->page('actualites')->children();

    foreach($actualites as $actuality) {
        if($actuality->date('Ymd') < $today) {
            $pasts[] = $actuality;
        }
        if($actuality->date('Ymd') >= $today && $actuality->date('Ymd') <= $today + 7) {
            $presents[] = $actuality;
        }
        if($actuality->date('Ymd') > $today + 7) {
            $futures[] = $actuality;
        }
    }
};

Can someone tel me what am I doing wrong ?

Thanks

Your controller doesn’t return anything:

return function($site, $pages, $page) {

    $today = date('Ymd');
    $actualites = $site->page('actualites')->children();

    foreach($actualites as $actuality) {
        if($actuality->date('Ymd') < $today) {
            $pasts[] = $actuality;
        }
        if($actuality->date('Ymd') >= $today && $actuality->date('Ymd') <= $today + 7) {
            $presents[] = $actuality;
        }
        if($actuality->date('Ymd') > $today + 7) {
            $futures[] = $actuality;
        }
    }
  return compact('actualites', 'pasts', 'presents', 'futures');
};

Indeed, noob me, and thanks a lot !