• Skip to primary navigation
  • Skip to main content

Chris Mcintosh

Full Stack Web Developer

  • Home
  • Blog

Using The Events Calendar Plugin with Timber and Twig

March 21, 2022 by chrismcintosh 2 Comments

  1. Ensure the Timber Plugin or Composer dependency is installed

  2. Install the Events Calendar Plugin

    This works for the free version. If using the paid version of the plugin – you might have to modify the other steps.

  3. Activate the Events Calendar Plugin

  4. Create the template file for the override

    Create a file at the following location inside the Timber theme tribe/events/v2/default-template.php

  5. Add the code to the template file

    See code snippet 1 below

  6. Render the markup in twig

    See code snippet 2

Code Snippet 1

<?php
/**
 * Default Events Template
 *
 * @package TribeEventsCalendar
 * @version 4.6.23
 *
 */

use Tribe\Events\Views\V2\Template_Bootstrap;

if ( ! defined( 'ABSPATH' ) ) {
	die( '-1' );
}

$context = Timber::get_context();
$context['tribe_markup'] = tribe( Template_Bootstrap::class )->get_view_html();
Timber::render( array( 'events.twig' ), $context );

Code Snippet 2

  <div class="events-container">
    {{tribe_markup}}
  </div>

More related information can be found here https://github.com/timber/timber/issues/312#issue-39623334

Filed Under: PHP, WordPress Tagged With: The Events Calendar, Timber, Twig

Reader Interactions

Comments

  1. scott taylor says

    July 11, 2022 at 3:52 pm

    Hi Chris, I got this mostly working using your solution above, but when I toggle over to the month view, no events are shown even though I have events. Do you know if I need to pass the $context into another template or view? also, the Day view doesn’t seem to work either.

    Thanks,
    Scott

    Reply
  2. chrismcintosh says

    August 25, 2022 at 6:28 pm

    Hi Scott,

    I’m just taking a guess but it might be due to the version of WP and Tribe Events you might using. I know there has been some things changing with the block based implementations vs classic editor.

    You might also check to see if you have css/js enabled for Tribe and ensure you dont have Skeleton theme selected for Tribe.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2023 · Genesis Sample on Genesis Framework · WordPress · Log in