Virtual page / custom route template

I’m attempting to create a virtual page as a sub-page of an existing page and am having problems rendering the template.

The existing page lives at /apply/ and my subpage is going to be called confirm-email.

The final path then is /apply/confirm-email/

I’ve added a route for this using this code, hooked on init:

add_action( 'init', function() {
    add_rewrite_endpoint(  'confirm-email', EP_ALL );

I’ve created a blade template at /views/confirm-email.blade.php.

It is a copy of other top-level templates:

  Template Name: Confirm Email page

@extends( '' )

  <h2>Confirm Form</h2>

I’m getting this to display in a fashion with the following code hooked on template_redirect

			function () {
		global $wp_query;

		if ( ! is_page( 'apply' ) || ! isset( $wp_query->query_vars[ 'confirm-email' ] ) ) {
        echo \Roots\view( 'confirm-email' );exit;

I’m getting output when i visit /apply/confirm-email/ but it doesn’t include the full page wrappers - no doctype, opening html tag, head section down to the

missing and the footer stuff - closing of the app div on down to closing html tag.

I’m obviously doing this wrong and hoping someone can set me on a better path.

You need to use the template_include hook instead of template_redirect

But since you’re using Acorn/Sage 10, I’d recommend just creating Laravel routes instead

Thanks @ben . I would like to use the Laravel route approach. Is there an example of this you can point me to in the docs? I’m not seeing anything specific to Acorn/Sage 10 regards setting up a route and related template.

There aren’t docs for it just yet, but I know I’ve seen a couple folks on here showing code/discussing it that you could search for

You could also purchase a Radicle license to see how it’s done

A follow up - the template_include did the job, thanks @ben . I’ve shot it and moved on but anxiously await a working example of using the laravel router to do the same thing using the sage 10 theme .

Added some basic docs: