Only use subpages in foreach loop, not as single subpage

I have tried searching, but bit difficult to describe, so apologies if this has been asked before.

On my site I have project testimonials. With a foreach loop I show a selection of these testimonials in a slider on the homepage and on the Testimonials page I show all of them in a list, again with a foreach loop.

Because each Testimonial is a subpage of the main Testimonials page, they can also be accessed as a single Testimonial on the frontend.

Is it possible to “hide” these single Testimonials from the frontend?

Thanks,
Pieter

Yes, you can create a route or a template that redirects any such URL to another page (the overview page, the home page or the error page).

For example, in your single testimonial.php template:

<?php go('whatever-page'); ?>

In a route:

c::set('routes', array(
  array(
    'pattern' => 'testimonials/(:any)',
    'action'  => function() {
      go('whatever-page');
    }
  )
));
1 Like

Thanks for your fast reply!

The thing is that there is no single testimonial.php template, only a blueprint

EDIT:
ah, okay, so with the route I can “exclude” it without the need for a single template to be present

As I said, either create that template with just that one line of code, or use the route.

1 Like

Sorry, I replied to quick.

Thanks so much, for both solutions!

I normally use

<?php go($page->parent()->url()) ?>

in the template file instead of a fixed uid;