Routing to a page with custom data

I’m trying my hand at routing and I’m not able to pass custom data to the template. In site/config/config.php, I have the following set based on the example in the docs:

c::set('routes', array(
  array(
    'pattern' => 'episodes/(:all)',
    'action'  => function($all) {
      $data = array(
        'placeholder' => $all,
        'foo' => '1',
        'bar' => '2'
      );
      return array('episode', $data);
    }
  )
));

In my browser, I can go to /episodes/hello, for instance, and the correct template renders, so that’s good. But I want to be able to access the data array from the function (along with the placeholder passed into the URL), which I’m not able to do. In the template, I have the following:

<p><?php echo $data['placeholder'] ?></p>
<p><?php echo $data['foo'] ?></p>
<p><?php echo $data['bar'] ?></p>

However, $data is just an empty array on the template. Am I missing something here?

This should work …

<p><?php echo $placeholder ?></p>
<p><?php echo $foo ?></p>
<p><?php echo $bar ?></p>
1 Like

Yep, that did the trick, thanks!