I want to define a custom route for https://mydomain.de/channel/CHANNEL_ID
. The page should then show some data for this channel.
I created a route in config.php
like this:
// channel page route
c::set('routes', array(
array(
'pattern' => array('channel/(:any)'),
'action' => function($channelId) {
$data = $channelId;
return array('channel', $data);
}
)
));
I created a template called channel.php
in the templates
folder. I created a channel.php
in the controllers
folder.
I need to pass the CHANNEL_ID
in the url to the controller to process some data there. This is what my controller code looks like right now:
return function($site, $pages, $page, $args) {
// get channel id from url path
$channelId = $args;
// DO SOME STUFF TO FETCH CHANNEL DATA
$channel = 'bar';
// return vars to use in template
return [
'channel' => $channel
];
};
Then I want to use the data generated there in my channel.php
template. Accessing it through the template variable $channel
.
However it currently does not work the way I am doing it. I guess there is something wrong with my route configuration? Can someone help?