Support

Home Forums Event Espresso Premium EE4 Theme Template Tags (But not exactly)

EE4 Theme Template Tags (But not exactly)

Posted: August 24, 2020 at 11:41 am


Jeff Phillips

August 24, 2020 at 11:41 am

Hello,

I am working on customizing content-espresso_events.php and content-espresso_events-venues.php. I have been using EE4 Theme Tags and very pleased with the results. I’m still somewhat new to template customization and am looking to see if I could get some help in displaying some information on our pages.

For many of the things I am trying to display, the information that is returned by the provided event or venue template tags, comes with additional data. As an example, “espresso_event_status()” seems to return a stylized button, or “espresso_venue_name()” seems to return the venue name, but within a <span itemprop=”name”>. Unfortunately this makes things not quite fit with my theme’s needs.

Are there any ways that I can simply get plain text, and only plain text, to be returned for the following items:

  • Event Status
  • Event Date Range (without time)
  • Event Registration Open Date/Time
  • Event Registration Close Date/Time
  • Venue Name
  • Venue Website URL

Thank you!


Tony

  • Support Staff

August 25, 2020 at 8:44 am

Hi there,

Sure there is, the template tags are essentially helper function that output the details as EE does currently. The majority of them use our Model System (or other helper functions which then use the model system etc) to build out the content they return, which you can find details of here:

https://github.com/eventespresso/event-espresso-core/tree/master/docs/G–Model-System

So to return just plain text, you’ll need to use the models yourself and pull whatever specific data you need, or for some you can pass parameters to the current helper functions to do what you need ‘Event Date Range (without time)’ would be an example of that.

The short answer is to use something like Kint Debugger wrap the $post or $event variable (depending on where you are working) in d() and then use that to view all of the available methods you have and work from there. (Heads up, there’s a lot methods as we’ve designed the model system to give developers easy access to various data).

—-

I’m not going to break down each helper function but I suggest you do so yourself to see how they pull the data in as it’ll help you more moving forward, but lets walk through the Event Status, which is this function:

function espresso_event_status( $EVT_ID = 0, $echo = TRUE ) {
    return EEH_Event_View::event_active_status( $EVT_ID, $echo );
}

So it calls the EEH_Event_View::event_active_status() helper function, so lets see what that does, in \event-espresso-core-reg\core\helpers\EEH_Event_View.helper.php

public static function event_active_status($EVT_ID = 0, $echo = true)
{
    $event = EEH_Event_View::get_event($EVT_ID);
    return $event instanceof EE_Event ? $event->pretty_active_status($echo) : 'inactive';
}

So for an EE_Event object, it calls pretty_active_status()

In \event-espresso-core-reg\core\db_classes\EE_Event.class.php

This method:

public function pretty_active_status($echo = true)
{
    $active_status = $this->get_active_status();
    $status = '<span class="ee-status event-active-status-'
              . $active_status
              . '">'
              . EEH_Template::pretty_status($active_status, false, 'sentence')
              . '</span>';
    if ($echo) {
        echo $status;
        return '';
    }
    return $status;
}

Looks like the get_active_statys() method returns a simply string and the ‘pretty’ version adds some additional output (this is true for all ‘pretty’ methods).

That means if you have an EE_Event object (its injected into the Global post) then you can do $event->get_active_status() to return a simple text string of the status.

Event Date Range (without time)

This is a little different, in that the template tags have parameters you can pass that allows you to remove the time output, this is the function:

espresso_event_date_range( $date_format = '', $time_format = '', $single_date_format = '', $single_time_format = '', $EVT_ID = FALSE, $echo = TRUE )

so espresso_event_date_range('', ' ', '', ' ', $event->ID()) would return a date range with no time set (as we set the time format to an empty string)

Event Registration Open Date/Time
Event Registration Close Date/Time

‘Registration Open/Close’ is from EE3, EE4 sets sale from/unti dates on the tickets themselves, but it’s not as simple as it was with EE3 (which had reg dates set on the event) as each individual ticket has its own dates.

How are you handling multi tickets in the setup?

Venue Name

Ideally, you should have EE_Event object and use the models to pull the related venue object from it (there are methods for doing so), then you can output whatever you want from the EE_Venue object.

Or, the template tags allow for this again, this template tag:

espresso_venue_name( $VNU_ID = 0, $link_to = 'details', $echo = TRUE )

So you can pass ‘none’ via $link_to to just get the venue name.

I don’t know of a template tag for this, so you’ll need the EE_Venue obect. Use either the EE_Event object to pull it, or look into the EEH_Venue_View::get_venue() method to pull it, then do

$venue->virtual_url();

The support post ‘EE4 Theme Template Tags (But not exactly)’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso