Add custom fields to tooltip in month view

Home Forums Calendar Products Events Calendar PRO Add custom fields to tooltip in month view

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #129073
    Ken
    Participant

    How would one go about adding the info from a custom field to the tooltip.php file for the month view?

    #129250
    Barry
    Member

    Hi – great question.

    As of 3.5 we’ve taken a new approach with regards to tooltips – largely to provide more flexibility with responsive layouts – and beyond recommending you check out the Themer’s Guide it’s probably well worth reading the fairly extensive documentation contained within the month/single-event.php template itself (and cross reference it with the new month/tooltip.php template).

    Does that help?

    #129265
    Ken
    Participant

    Not Really.
    I have already looked at both of those php files before posting here. I do not see how to go about updating them for the custom fields. I have already placed them in my corresponding theme folder.

    #129548
    Ken
    Participant

    Hi Barry,
    After looking at it fresh this morning, I think I was overthinking things yesterday.
    The field I wanted to add is called “Time Zone” in the ECP settings. So I was trying to figure out how to add in this string with the [[ myString ]] samples that were in the single-event.php file. By doing something like this:

    $additional_data = array();
    $zone = tribe_get_custom_field('Time Zone'); 
    $additional_data['zone'] = $zone;
    echo tribe_events_template_data( $post, $additional_data );

    Then I realized I could just add in the php I needed to the tooltip.php file where I wanted the data to appear.
    So I added this in:

    <?php
    $zone = tribe_get_custom_field('Time Zone');
    if(!empty($zone)) {
    echo ' (' . $zone . ')' ;
    ?>

    So I have it working now. But I am still not clear on the bracket code and how to get that to work instead. Am I doing it correctly? Just because it works doesn’t mean I am doing it correctly.

    #129618
    Barry
    Member

    Well, tooltip.php is a PHP template but it is ultimately used to generate a Javascript template.

    So, you only get one chance to modify it server-side and if you echo out a piece of text (in your case, the time zone custom field) that means it will be used in every tooltip (ie, the same timezone will appear in all tooltips). Conversely, if you use a template variable like [[=title]] this can be populated appropriately within the browser environment – that’s why this approach is used.

    Does that make more sense?

    #129630
    Ken
    Participant

    Ah ok…I didn’t check that against other zones, I thought it was just too easy.
    So back to the drawing board for me :0)

    So I’m back to the question how do I create that template variable?
    Where does the code go so that [[=zone]] will work when I place it in tooltip.php?
    I’m just not getting it.

    #129815
    Shaun
    Participant

    I am looking to do something similar too. The documentation online and in the single-event.php are great at explaining how it works, but not how to do it.

    How can we add additional data to be generated in json? I assume tribe_events_template_data() comes into play…but where can we add new strings? In functions.php?

    #129838
    Ken
    Participant

    Jesse, I got it worked out.
    These changes go inside the month/single-event.php I put mine at lines 23-25

    $additional_data = array();
    $somestringname = tribe_get_custom_field('Your Custom Field'); 
    $additional_data['bracketname'] = $somestringname;

    Then at line 194 change the “data-tribejson” part to include additional_data like this:
    data-tribejson='<?php echo tribe_events_template_data( $post, $additional_data );

    Then in the month/tooltip.php add your brackets and the name you chose [[=bracketname]]
    I hope that helps and makes sense.

    #131202
    Shaun
    Participant

    Thanks!!

    #135107
    Barry
    Member

    Well done all 🙂

Viewing 10 posts - 1 through 10 (of 10 total)
  • The topic ‘Add custom fields to tooltip in month view’ is closed to new replies.