Title: Passing event start to custom function
Last modified: August 22, 2016

---

# Passing event start to custom function

 *  [eclev91](https://wordpress.org/support/users/eclev91/)
 * (@eclev91)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/passing-event-start-to-custom-function/)
 * I’ve written my own theme for Ai1EC and have also hooked up a Twig function to
   determine if it is too late for someone to register for an event.
 * If I simply do `{{ event.get('start') }}` from `event-single.twig`, it prints
   a timestamp, exactly what I need. However, if I pass that to my function like
   so:
 * `{% if expired(event.get('start')) %}`
 * and print the argument from the function, I end up with an Ai1ec_Date_Time object.
   How can I pass the timestamp I’m looking for here?
 * [https://wordpress.org/plugins/all-in-one-event-calendar/](https://wordpress.org/plugins/all-in-one-event-calendar/)

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [cefiar](https://wordpress.org/support/users/cefiar/)
 * (@cefiar)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/passing-event-start-to-custom-function/#post-5347661)
 * This will most likely depend on the twig code around it (eg: is it in a for loop,
   and what you are iterating in the loop), and which twig file you’re editing (
   as they all are influenced by where they’re called from).
 * eg: **event-single.twig** is a special case compared to the others, as it only
   displays one event at a time, whereas other views need to handle multiple events.
   This isn’t the only ones with differences however.
 *  Thread Starter [eclev91](https://wordpress.org/support/users/eclev91/)
 * (@eclev91)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/passing-event-start-to-custom-function/#post-5347670)
 * I can do them right next to each other, like so:
 *     ```
       <div class="col-md-12">
       			{{ event.get('start') }}
       			{% if expired( event.get('start') ) %}
       				<span class="register-for-event expired">Registration Closed</span>
       			{% else %}
       				<a class="register-for-event replace-me" data-event-id="{{ event.get( 'post_id' ) }}" href="">Register</a>
       			{% endif %}
       		</div>
       ```
   
 * And I still get two different things. I’m calling the same function on the same
   object in the same context it seems.
 *  [cefiar](https://wordpress.org/support/users/cefiar/)
 * (@cefiar)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/passing-event-start-to-custom-function/#post-5347680)
 * I haven’t played with setting up functions (Time.ly are currently documenting
   the way to do this with within a calendar child theme, rather than by editing
   the core code), but I’ve played a lot with twig.
 * You might try:
 *     ```
       {% if expired( event.get('start') | raw ) %}
       ```
   
 * Or:
 *     ```
       {% set startevent = event.get('start') %}
       {% if expired( startevent ) %}
       ```
   
 * Note: What is expired supposed to spit out? The `if` is expecting true/false 
   only.
 *  Thread Starter [eclev91](https://wordpress.org/support/users/eclev91/)
 * (@eclev91)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/passing-event-start-to-custom-function/#post-5347682)
 * I haven’t edited any core code – I used their functions to grab the global Twig
   Environment from the site’s core plugin, then use `new Twig_SimpleFunction()`
   and so on. I hate to edit core files.
 * Neither of those solutions worked, unfortunately, but it did occur to me that
   echoing the object resulted in a string, so there must be a method doing it somewhere.
   That led me to the `__toString()` method in the Ai1EC_Date_Time class, which 
   got me what I needed, so I ended up with
 * `strtotime($date->__toString())`
 * It did exactly what I wanted. Thanks for taking the time to address my question.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Passing event start to custom function’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/all-in-one-event-calendar.svg)
 * [Timely All-in-One Events Calendar](https://wordpress.org/plugins/all-in-one-event-calendar/)
 * [Support Threads](https://wordpress.org/support/plugin/all-in-one-event-calendar/)
 * [Active Topics](https://wordpress.org/support/plugin/all-in-one-event-calendar/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/all-in-one-event-calendar/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/all-in-one-event-calendar/reviews/)

## Tags

 * [ai1ec](https://wordpress.org/support/topic-tag/ai1ec/)
 * [function](https://wordpress.org/support/topic-tag/function/)

 * 4 replies
 * 2 participants
 * Last reply from: [eclev91](https://wordpress.org/support/users/eclev91/)
 * Last activity: [11 years, 8 months ago](https://wordpress.org/support/topic/passing-event-start-to-custom-function/#post-5347682)
 * Status: not resolved