The Events Calendar and Sage 9 (blade)

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:

<script>
$('.tribe_events.status-publish').each(function() {
      var tribeJson = $(this).data('tribejson');
      console.log(tribeJson);
      var eventUrl = tribeJson.permalink,
          eventTitle = tribeJson.title,
          eventThumb = tribeJson.imageTooltipSrc,
          eventTime = tribeJson.dateDisplay,
          eventDesc = tribeJson.excerpt;
      $(this).append('<div class="tribe-events-tooltip" style="bottom: 50px; display: none; opacity: 1;"><a class="url" href="'+eventUrl+'" title="'+eventTitle+'" rel="bookmark"><h4 class="entry-title summary">'+eventTitle+'</h4></a>	<div class="tribe-events-event-body"><div class="tribe-event-duration"><a class="url" href="'+eventUrl+'" title="'+eventTitle+'" rel="bookmark"><abbr class="tribe-events-abbr tribe-event-date-start">'+eventTime+' </abbr></a></div> <div class="tribe-events-event-thumb"><a class="url" href="'+eventUrl+'" title="'+eventTitle+'" rel="bookmark"><img src="'+eventThumb+'" alt="'+eventTitle+'"></a></div><div class="tribe-event-description">'+eventDesc+'</div><span class="tribe-events-arrow"></span></div></div>');
    });
</script>

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:

{{--
  Template Name: Events Template
--}}

@extends('layouts.app')

@section('content')
    <main id="tribe-events-pg-template"
          class="tribe-events-pg-template">
        {!!Tribe__Events__Templates::load_ecp_into_page_template() !!}
    </main>
@endsection
2 Likes

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.

{{--
  Template Name: Events Template
--}}

@extends('layouts.app')

@section('content')
    <main id="tribe-events-pg-template"
          class="tribe-events-pg-template">
        @while(have_posts()) @php the_post() @endphp
        @php the_content() @endphp
        @endwhile
    </main> <!-- #tribe-events-pg-template -->
@endsection

Right now, we solve this by ignoring their complete HTML for specific pages and loading our own like so:

add_filter('tribe_template_html', function($html, $file, $name, $that) {
    if ($name[0] === 'single-event-blocks') {
        return template('tribe.events.single-event-blocks', ['that' => $that]);
    }
    return $html;
}, 999, 4);

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.

1 Like

Anyluck with sage 10, i tried to implemented this plugin but no luck. Thanks

1 Like

@timothy_m_alber @mangcoding did you or anyone manage to get it working with Sage 10?

no, i use my own using ACF :). no luck with the plugins. too much customizing and i don’t need all the feature of event calendar.

https://master-flight-training.org/webinar

i only use vueJS and ACF

Not exactly, but for what we need and since we heavily customize the templates anyway, just including something this on whatever events template you set (I usually set the default option the way @MWDelaney mentioned) works for our need:

@include('tribe-events.'. basename(tribe_get_current_template(),'.php'))

I’m curious if you’ve used this on Sage 10 or recently with The Events Calendar. I’m having issues getting blade to work with it. I’ve tried adding Tribe__Settings_Manager::set_option( ‘tribeEventsTemplate’, ‘views/template-events.blade.php’ ); to app/theme/filters.php. I’ve tried adding the default template, but it didn’t work. I would greatly appreciate your help if you have any insight. Thank you.

This is what I use for sage 9. It works, but i’m not happy with it. TEC 5 has a new template engine and hooks that might allow a nicer solution.

This worked for me but here is a hint… Make sure you clear the _transient_tribe_cache… entries in the database because the changes you make in the templates in [theme]/resources/ will not show when developing locally. I spent several hours figuring this out so I hope it helps someone else…

I solved this by creating an events.blade.php in the resources folder.

I then pasted the following:

{{--
  Template Name: Events
--}}

<?php use Tribe\Events\Views\V2\Template_Bootstrap; ?>

@extends('layouts.fullwidth')

@section('content')
  <div id="tribe-events-pg-template">
	<?php echo tribe( Template_Bootstrap::class )->get_view_html(); ?>
  </div> <!-- #tribe-events-pg-template -->
@endsection

And this replicated the same content seen on the default-template.php override in the V2 edition of the plugin. It has all functionality includeing the nice styling, datepickers etc.

Hope that helps!

Phil

4 Likes

Is this working on Sage 10? I dropped this in and can select the template within TEC settings, but cant include any partials from here. Is there something else that I’m missing? Seems that a lot of the stuff talked about in the above comments pertain to sage 9.

I don’t think this will work for sage 10. There’s a lot changed in sage 10 and the events calendar as well. The code I posted is made for the ‘old’ (the not /v2/ templates) the event calendar templates.
The new the events calendar template logic has more useful hooks I assume, but I haven’t takem an a look at it.

1 Like

Sage10 support for The events calendar v2 templates. This is a work in progress but at least it works.

2 Likes

A recent TEC update broke my method above. This is the better solution! Thank you for this!

1 Like

I’m running into an issue getting TEC to run in my Sage 10 environment. Currently trying to get things working using the supermundano/sage-the-events-calendar package. However, I’m stuck on the wp acorn vendor:publish --tag="TheEventsCalendar Templates" step. When I run it, I get the following error in my console:

In VendorPublishCommand.php line 277:
                                                                        
  Call to undefined function Illuminate\Foundation\Console\base_path() 

Just curious if you or others have encountered this error. Not sure where I’m going wrong.

EDIT: Is it possible the supermundano/sage-the-events-calendar package is intended to be used within the Roots Bedrock environment? I’m not using Bedrock; not sure if that’s related to this issue or not.