This looks like a slightly different challenge than WooCommerce, because TEC wants to choose a Page template (default or a custom template), and sees the templates just fine, but only shows a stripped down “Archive” view of the events no matter which template is chosen.
How can I troubleshoot and/or work around this issue in a way that’s helpful to the Sage project? Is there specific information I can provide?
For troubleshooting these issues, I’ve found it helpful to just var_dump($templates); in wp-includes/template.php#L42
You’ll get something that looks like this (normally it’s not doubled up like this, but this seems to be happening on events archives pages with that plugin):
This is more or less a list of what files it’s sending to locate_template() in wp-includes/template-loader.php.
Each new block of file names from the var_dump() could be an indicator that the return value from locate_template() (in each of the get_{type}_template() from template-loader.php) was falsy.
For the particular plugin you’re discussing, the best solution is to probably create an events.blade.php file in your templates directory with the following contents:
If you need further refinement, then create a templates/tribe-events/ folder and have at it. If you want to use blade for these, then you’ll need to basically copy how we implemented blade for WordPress core (see sage/src/filters.php), and even then I’m not sure if it would work; it might cause the plugin to shit its pants.
Here’s a neat thing I found: I can automatically set the The Events Calendar default template using their settings class, so that I never see the error that started this thread:
/**
* Set the The Events Calendar default template to our Sage-friendly template.
**/
Tribe__Settings_Manager::set_option( 'tribeEventsTemplate', 'views/template-events.blade.php' );
This is what i’m using now for the event calendar:
Essentially removing everything thats included by the event calendar and rendering it again with blade. A huge waste of resources. If anyone has another solution, let me know!
The first filter alone allows for overwrites to be placed in /resources/views/tribe-events/, but doesn’t enable blade.
Thanks! This did the trick and it was the shortest path from A to B.
Only problem was Tribe’s js template, ‘/src/views/month/tooltip.php’. In case anyone else runs into this issue (tooltip markup not generated in month view), the tooltip markup can be easily recreated client-side:
I had a bit of trouble with this, as the events calendar was doing something funky with the standard wp_query data. I found that the following worked as expected:
Actually, still had problems with my previous template. I’ve found that the following snippet works as it will fire all of the hooks defined in the Tribe__Events__Templates::setup_ecp_template() function and handle all the “ninja magic” mentioned there.
Not sure if anyone else has had this problem, but it looks like it’s working as expected for me now.
Needs refactoring, especially to make the default blade filters and Controllers work again, but it was a quick solve to use our custom template for a single event.
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.
Anyone had success using tribe events templates in Sage 10? Have an upcoming project we’d like to use TEC with it, but having some trouble leveraging a template in Sage 10 as the default TEC events template.