# The Events Calendar and Sage 9 (blade)

**URL:** https://discourse.roots.io/t/the-events-calendar-and-sage-9-blade/8667
**Category:** sage
**Created:** 2017-01-26T21:48:27Z
**Posts:** 36

## Post 1 by @MWDelaney — 2017-01-26T21:48:27Z

## UPDATE: See the marked solution for both Sage 9 and Sage 10!

[Like WooCommerce before it](https://discourse.roots.io/t/woocommerce-blade-sage-9/8449) The Events Calendar by Tribe doesn’t want to play nice with Blade templates.

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?

---

## Post 2 by @MWDelaney — 2017-01-30T02:36:20Z

Just a quick confirmation that `$template` variable at the `/events/` slug is `index.blade.php`, and on an individual event it’s `single.blade.php`.

---

## Post 3 by @QWp6t — 2017-01-30T08:38:23Z

For troubleshooting these issues, I’ve found it helpful to just `var_dump($templates);` in **wp-includes/template.php#L42**

> <https://github.com/WordPress/WordPress/blob/master/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):

![](https://discourse.roots.io/uploads/default/original/2X/c/c016ab9723a811250bee598fe8e8cb3d68dc1829.png)

This is more or less a list of what files it’s sending to `locate_template()` in **wp-includes/template-loader.php**.

> <https://github.com/WordPress/WordPress/blob/master/wp-includes/template-loader.php#L45-L65>

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.

I hope that makes sense.

---

## Post 4 by @QWp6t — 2017-01-30T08:38:35Z

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:

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

@extends('layouts.base')

@section('content')
  <div id="tribe-events-pg-template">
	<?php tribe_events_before_html(); ?>
	<?php tribe_get_view(); ?>
	<?php tribe_events_after_html(); ?>
  </div> <!-- #tribe-events-pg-template -->
@endsection
```

Be sure to select it in the admin panel.

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.

---

## Post 5 by @MWDelaney — 2017-01-30T14:06:19Z

This did the trick. Thank you!

Going forward perhaps the docs could include basic snippets and info for common plugins like The Events Calendar, WooCommerce, etc? Just a thought.

I really appreciate your time on this!

---

## Post 6 by @QWp6t — 2017-01-30T22:34:38Z

Both WooCommerce and The Events Calendar document how to do this. It’s just standard implementation of these respective plugins. [The Events Calendar is doing something slightly wrong](https://github.com/moderntribe/the-events-calendar/pull/1268), though, in my opinion.

---

## Post 7 by @MWDelaney — 2017-07-07T15:27:26Z

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' );
```

---

## Post 8 by @pi_mont — 2017-07-07T16:14:48Z

Nice, I’m about to use TEC on a Sage 9 project, so this will definitely come in handy.  
Thanks!

---

## Post 9 by @timothy_m_alber — 2018-03-14T20:38:55Z

Have you ever had to move the whole tribe-events views folder to edit multiple tribe files?

---

## Post 10 by @jchck — 2018-08-01T19:50:35Z

@timothy_m_alber I have.

In Sage 9, putting events calendar template overrides in the resources dir seems to do the trick:

```
./resources/tribe-events/{tribe-template-to-override}.php
```

---

## Post 11 by @Xilonz — 2019-01-15T23:04:51Z

This is what i’m using now for the event calendar:

> <https://gist.github.com/Xilonz/8f6192dccf9f6349ad40a7b3395c9648>

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.

---

## Post 12 by @Greg_Hollowell — 2019-03-15T20:41:59Z

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>
```

---

## Post 13 by @WildPress — 2019-03-20T22:14:46Z

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
```

---

## Post 14 by @WildPress — 2019-05-22T11:29:28Z

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
```

---

## Post 15 by @kero — 2019-05-22T11:47:30Z

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.

---

## Post 16 by @codepuncher — 2019-09-27T22:58:07Z

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.

---

## Post 17 by @timothy_m_alber — 2019-10-28T18:50:21Z

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.

---

## Post 18 by @mangcoding — 2019-11-12T12:57:15Z

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

---

## Post 19 by @huub — 2019-12-10T21:23:21Z

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

---

## Post 20 by @mangcoding — 2019-12-11T01:23:37Z

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](https://master-flight-training.org/webinar)

i only use vueJS and ACF

---

## Post 21 by @timothy_m_alber — 2019-12-19T22:04:53Z

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'))
```

---

## Post 22 by @pjolley — 2020-02-25T17:25:03Z

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.

---

## Post 23 by @Xilonz — 2020-02-27T15:08:47Z

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.

> <https://gist.github.com/Xilonz/8f6192dccf9f6349ad40a7b3395c9648>

---

## Post 24 by @toddsantoro — 2020-07-20T15:57:33Z

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…

---

## Post 25 by @PhilOwen — 2020-09-11T14:03:52Z

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

---

## Post 26 by @joecamel9166 — 2020-12-05T05:40:19Z

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.

---

## Post 27 by @Xilonz — 2020-12-05T09:33:24Z

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.

---

## Post 28 by @carlosfaria — 2021-04-14T17:36:01Z

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

> **[supermundano/sage-the-events-calendar](https://github.com/supermundano/sage-the-events-calendar)**
>
> Add The Events Calendar support to Sage 10. Contribute to supermundano/sage-the-events-calendar development by creating an account on GitHub.

---

## Post 29 by @MWDelaney — 2021-06-25T13:15:14Z

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

---

## Post 30 by @dev — 2021-06-30T01:32:57Z

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.

---

## Post 31 by @sabelapaulo — 2021-07-04T06:39:10Z

Having same problem, but I’m using bedrock (and Trellis).

Using Sage 10, I did a `composer require supermundano/sage-the-events-calendar` in the Sage root directory (not Bedrock in this case, correct?).

I logged into via `trellis ssh development`, `cd /srv/www/example.com/current`, and the `wp acorn package:discover` seemed to go OK (it discovered the plugin), but I got the exact same error.

Being pretty uniformed about acorn at the moment, I pretty much don’t have a clue what to do next.

Were you able to come up with any solutions?

---

## Post 32 by @dev — 2021-07-04T15:55:52Z

I believe the publish step simply moves the `default-template.blade.php` into `[your-theme]/resources/views/tribe/events/v2/`, so if the publish step isn’t working for you, you can do it manually.

(I was running into some issues after that due to running things in Windows environment locally (Windows file paths can have back slashes instead of forward slashes), but the plugin should be updated now to work with both Mac/Linux and Windows.)

---

## Post 33 by @dev — 2021-07-04T15:57:20Z

And I believe you are correct about `composer install`ing it into the Sage theme root directory, as that’s what I did. I’m not running Bedrock, nor Trellis.

---

## Post 34 by @mikeylythcott — 2022-01-16T10:20:44Z

Does anyone have a step by step way to get this work with Sage9 (yes, 9, not 10). I have a Sage 9 site that needs TEC

---

## Post 35 by @ben — 2022-01-16T18:13:13Z

What is not working from the steps already provided in this topic?

> [@The Events Calendar and Sage 9 (blade)](https://discourse.roots.io/t/the-events-calendar-and-sage-9-blade/8667/4):
>
> 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: {{-- Template Name: Events --}} @extends('layouts.base') @section('content') \<div id="tribe-events-pg-template"\> \<?php tribe\_events\_before\_html(); ?\> \<?php tribe\_get\_view(); ?\> \<?php tribe\_events\_after\_html(); ?\> \</div\> \<!-- #tribe-events-pg-template --\> @endsection Be sure to select it in the admin panel. If you need…

---

## Post 36 by @josialoos — 2022-02-28T15:04:32Z

wow thanks this was super helpfull for getting V2 to work!
