supermundano / sage-the-events-calendar

Add The Events Calendar support to Sage 10.
MIT License
12 stars 9 forks source link

How to include different files based on Single event view? #1

Closed ghost closed 3 years ago

ghost commented 3 years ago

I was facing this question earlier and figured it out. I'm sharing the answer below in case anyone else needs to know this information.

As per the instructions in this repo, a single blade template is broadcast into our resources folder at <theme>/resources/views/tribe/events/v2/default-template.blade.php.

This template is used for both the monthly/list events view and single events views. In order to determine which view we are in, we call the method is_single_event on the class Template_Bootstrap (for the full method docs see here). This method returns a boolean value. We can evaluate this value using an if conditional statement to include different files depending on whether we are in a single event view.

@php
use Tribe\Events\Views\V2\Template_Bootstrap;
@endphp

@extends('layouts.app')

@section('content')

    @if(tribe( Template_Bootstrap::class )->is_single_event())
        {{-- Conditionally display something if we are in a single event --}}
    @else
        {{-- Conditionally display something if we are *not* in a single event --}} 
    @endif

    {!! tribe( Template_Bootstrap::class )->get_view_html(); !!}

@endsection