I'm using the builder plugin to show overview and detail pages. The structure is very simple, it's just an overview page with url: products, and a detail page with url products/:slug.
This works fine as long as I use existing products, with existing URLs. However when I enter something random as the slug it still goes to the page but just displays nothing. I would like it to redirect to the 404 page to give the user a nicer experience. I could add something like this to the template of every detail page but that seems very ugly and I don't want to add so much logic to my templates.
function onEnd()
{
if (!$this['builderDetails']->record) {
$this->setStatusCode(404);
return $this->controller->run('404');
}
}
Is there any built-in behaviour like this in the Builder plugin? Or is there another nicer way to achieve this?