The Events Calendar and Sage 9 (blade)

I’ve been having a tinker to see how close I could get to solving this (similarly to sage-woocommerce).
Using this, I’ve managed to output some templates with Controller support:

<?php

declare(strict_types=1);

namespace App\Plugins;

use function App\template;

class EventsCalendar
{
    public function run(): void
    {
        $this->addFilters();
    }

    public function addFilters(): void
    {
        add_filter('tribe_get_current_template', [self::class, 'setupTemplates'], PHP_INT_MAX);
        add_filter('tribe_get_template_part_path', [self::class, 'setupTemplates'], PHP_INT_MAX);
    }

    public static function setupTemplates(string $original_template): string
    {
        $template = basename($original_template);
        $view = basename(dirname($original_template));
        $view_template = "{$view}/{$template}";
        $data = collect(get_body_class())->reduce(function ($data, $class) use ($template) {
            return apply_filters("sage/template/{$class}/data", $data, $template);
        }, []);
        $location_paths = [
            "tribe-events/{$view_template}",
            "tribe-events/{$template}",
            $template,
        ];
        $template = \App\locate_template($location_paths);

        if ($template) {
            // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
            echo template($template, $data);
            return get_stylesheet_directory() . '/index.php';
        }

        return $original_template;
    }
}

The only problem is that there are a fair few template parts in Events Calendar that when trying to load will give the error “Fatal error: Allowed memory size of xxxxx”.

Unfortunately, I haven’t really figured that bit out…

But I hope this may help someone get closer to complete support with Blade+Controllers!

Edit:
One of the issues I had was using a custom events template.
Using a custom event template (chosen in Events Calendar settings) would provide strange results (e.g. get_the_ID() returns 0).
Using the default template and overriding in the theme provides more consistent results.