Conditional tags and for-loops

EME provides the use of conditional tags and for-loops.

Conditional tags

Sometimes you want info only to be shown dependent on some conditions. In almost all formatting settings, you can use a special shortcode called [eme_if] that allows these kind of decisions:
You can use all placeholders in the if-part, just by prepending them with “ESC”, e.g you could use this for single event formatting:


#j, #M #Y – #H:#i
#_NOTES
[eme_if tag='#ESC_ATT{color}' value='red'] color: #_ATT{color} [/eme_if]
[eme_if tag='#ESC_ATT{price}'] price: #_ATT{price} [/eme_if]
[eme_if tag='#ESC_TOWN'] the town is: #_TOWN [/eme_if]
[eme_if tag="#ESC_ATT{Image URL}"] <img src=”#_ATT{Image URL}” /> [/eme_if]
[eme_if tag="#ESC_STARTDATE" value="#ESC_ENDDATE"] The start and end date of this event are the same, so just showing start: #_STARTDATE [/eme_if]
[eme_if tag="#ESC_{j M Y}" value="#ESC@_{j M Y}"] The start and end date of this event are the same: #j #M #Y [/eme_if]
[eme_if tag="#ESC_{j M Y}" notvalue="#ESC@_{j M Y}"] This date is only printed if different from start date: #@_{- j M Y} [/eme_if]


The possible conditions you can test for are:

  • Nothing, you then just check that the placeholder/string mentioned in the tag is not empty: [eme_if tag='#ESC_TOWN']
  • is_empty=1 checks that the placeholder/string mentioned in the tag is in fact empty: [eme_if tag='#ESC_TOWN' is_empty=1]
  • value or eq checks if the placeholder/string mentioned in the tag is the same as the one mentioned in value:
    [eme_if tag='#ESC_ATT{color}' eq='red'] color: #_ATT{color} [/eme_if]
  • notvalue or ne checks if the placeholder/string mentioned in the tag has a value different than the one mentioned in value
  • lt checks if the numerical value of the placeholder/string mentioned in the tag has a value lower than the one mentioned in lt
  • le checks if the numerical value of the placeholder/string mentioned in the tag has a value lower than or equal to the one mentioned in lt
  • gt checks if the numerical value of the placeholder/string mentioned in the tag has a value bigger than the one mentioned in gt
  • ge checks if the numerical value of the placeholder/string mentioned in the tag has a value bigger than or equal to the one mentioned in gt
  • contains checks if the value of the placeholder/string mentioned in the contains occurs in the one mentioned in tag
  • notcontains checks if the value of the placeholder/string mentioned in the notcontains doesn’t occur in the one mentioned in tag
  • incsv checks if the value of the placeholder/string mentioned in the incsv occurs in the comma-separated list mentioned in tag
  • notincsv checks if the value of the placeholder/string mentioned in the incsv does NOT occur in the comma-separated list mentioned in tag

As extra, next to the regular placeholders you can use, I added some extra placeholders:

  • #_IS_AUTHOR (‘1’ if you’re the author for the event, ‘0’ otherwise)
  • #_IS_CONTACTPERSON (‘1’ if you’re the contact person for the event, ‘0’ otherwise)
  • #_IS_AUTHOR_OR_CONTACTPERSON (‘1’ if you’re the author or contact person for the event, ‘0’ otherwise)
  • #_IS_PRIVATE_EVENT (‘1’ if the event is a private event, ‘0’ otherwise)
  • #_IS_RSVP_ENABLED (‘1’ if the event is RSVP-able, ‘0’ otherwise)
  • #_IS_RECURRENT_EVENT (‘1’ if the event is part of a recurrence, ‘0’ otherwise)
  • #_IS_REGISTERED (‘1’ if WP user has already registered for the event, ‘0’ otherwise)
  • #_IS_MULTIPRICE (‘1’ if the event is a multiprice event, ‘0’ otherwise)
  • #_IS_MULTISEAT (‘1’ if the event is a multiseat event, ‘0’ otherwise)
  • #_IS_MULTIDAY (‘1’ if the event start date is different from the end date, ‘0’ otherwise)
  • #_IS_MULTIBOOKING (‘1’ when actually doing a multi-booking, not when updating/confirming/deleting a booking)
  • #_IS_ALLDAY (‘1’ if the event is a all-day event, ‘0’ otherwise)
  • #_IS_ATTENDANCE (‘1’ if the event only takes rsvp attendances, ‘0’ otherwise)
  • #_IS_RSVP_ENDED (‘1’if the registration period has passed, ‘0’ otherwise)
  • #_IS_FIRST_RECURRENCE (‘1’if the event is the first event in a recurrence series, ‘0’ otherwise)
  • #_IS_LAST_RECURRENCE (‘1’if the event is the last event in a recurrence series, ‘0’ otherwise)
  • #_IS_ENDED_EVENT (‘1’if the event has ended, ‘0’ otherwise)

A number of generic placeholders can be used even outside event/location/member formatting templates (in other words: when you use eme_if standalone on a wordpress page). These are:

  • #_IS_USER_IN_GROUP{xxx} returns ‘1’if the logged in WP user is in the EME group called ‘xxx’, ‘0’ otherwise. Multiple groups can be specified, separated by “,”.
  • #_IS_USER_MEMBER_OF{xxx} returns ‘1’if the logged in WP user is an active member of the EME membership called ‘xxx’, ‘0’ otherwise. Multiple memberships can be specified, separated by “,”.
  • #_IS_USER_MEMBER_PENDING{xxx} returns ‘1’if the logged in WP user is a member with status pending of the EME membership called ‘xxx’, ‘0’ otherwise. Multiple memberships can be specified, separated by “,”.
  • #_IS_USER_MEMBER_EXPIRED{xxx} returns ‘1’if the logged in WP user is a member with status expired of the EME membership called ‘xxx’, ‘0’ otherwise. Multiple memberships can be specified, separated by “,”.
  • #_USER_HAS_ROLE{xxx} returns ‘1’if the logged in WP user is has the WP role called ‘xxx’, ‘0’ otherwise. Multiple roles can be specified, separated by “,”.
  • #_USER_HAS_CAP{xxx} returns ‘1’if the logged in WP user is has the WP capability called ‘xxx’, ‘0’ otherwise. Multiple capabilities can be specified, separated by “,”.
  • #_IS_SINGLE_DAY returns ‘1’ if you’re viewing a single day, ‘0’ otherwise
  • #_IS_SINGLE_EVENT returns ‘1’ if you’re viewing a single event details, ‘0’ otherwise
  • #_SINGLE_EVENTPAGE_EVENTID if viewing a single event, it will return the event id, empty otherwise
  • #_IS_SINGLE_LOC returns ‘1’ if you’re viewing a single location details, ‘0’ otherwise
  • #_IS_ADMIN_PAGE returns ‘1’ if on the admin pages, ‘0’ otherwise
  • #_IS_RSVP_PASSWORD_ENABLED returns ‘1’ if the event being watched is RSVP password protected, ‘0’ otherwise
  • #_CURDATE if you want to compare the current date in YYYY-MM-DD format
  • #_CURTIME if you want to compare the current date in HH:MM format
  • #_IS_LOGGED_IN returns ‘1’ if user is logged into WP, ‘0’ otherwise
  • #_LOCALE returns the current locale
  • #_LANG returns the current language
  • #_UNSUB_URL returns the unsubscribe url for mailings
  • #_MEMBERSHIP_PAYMENT_URL{xx} (with ‘xx’ being the name or id of a membership), returns the payment url of a member if the person is logged in and an pending or active member of the mentioned membership
  • #_EXPIRED_MEMBERSHIP_PAYMENT_URL{xx} (with ‘xx’ being the name or id of a membership), returns the payment url of a member if the person is logged in and an expired member of the mentioned membership

Example usage:
[eme_if tag='#_IS_LOGGED_IN' value='0'] You are NOT logged in [/eme_if]
[eme_if tag='#_IS_LOGGED_IN' value='1'] You are logged in [/eme_if]
[eme_if tag='#ESC_CATEGORIES' contains='red'] The event is in at least the red category [/eme_if]
[eme_if tag="#ESCj #ESCM #ESCY" value="#ESC@j #ESC@M #ESC@Y"] The start and end date of this event is the same, so just showing start: #j #M #Y [/eme_if]
Or, print start date, and print end date only if different : #_STARTDATE [eme_if tag="#ESC_STARTDATE" notvalue="#ESC_ENDDATE"] #_ENDDATE [/eme_if]
A variant of the above, using curly brackets:
[eme_if tag="#ESC_{j M Y}" value="#ESC@_{j M Y}"] The start and end date of this event is the same: #{j M Y} [/eme_if]
Print start date, and print end date only if different:
#_{j M Y} [eme_if tag="#ESC_{j M Y}" notvalue="#ESC@_{j M Y}"] #@_{- j M Y} [/eme_if]
Print the list of attendees if at least one person signed up:
[eme_if tag='#_AVAILABLESEATS' lt='#_TOTALSEATS']<p>The following people have signed up for this event:#_ATTENDEES</p>[/eme_if]

Using this conditional tag requires some playing around …
I also added [eme_if2], [eme_if3], [eme_if4] … till [eme_if15], if you want to use more than one level of logic (wordpress doesn’t like a shortcode with the same name enclosed in another one).

For-loops

Using the shortcode [eme_for], you can use a for-loop to show specific info a number of times. Usage for this might be e.g. to show images for the number of seats taken, instead of a number.
The required options are either:

  • min=x with ‘x’ being the lowest number in the for-loop
  • max=y with ‘y’ being the highest number in the for-loop

or:

  • list=xxx xxx being a list of values, separated by a separator specified by the sep-option (see below)
  • sep=y the separation char for the list above (default “,”)

In both shortcodes you can use the extra following placeholders to play with the values of the loop: #_LOOPCOUNTER and #_LOOPVALUE

Some examples:
[eme_for min='1' max='5']Do anyting here, it will be repeated 5 times[/eme_for]
[eme_for min='1' max='#_RESERVEDSEATS']Do anyting here, it will be repeated for each reserved seat[/eme_for]
An example where a custom formfield containing multiple values is being looped:
[eme_for list="#_FIELD{mycustomlist}" sep="||" ]This is the #_LOOPCOUNTER value in the list: #_LOOPVALUE

[/eme_for]
The latter shows that you can also loop through e.g. the categories of an event of a custom location field and show that info in any way you want on a page. If you want to use the loop value for an url, you can also use #URL_LOOPVALUE