FAQ Q207: How can I have Planyo print texts in templates conditionally?

Sekcja: Templates, tags and CSS styles
Conditional statements can be used in any template. They allow you to print different code based on a value of any tag. Conditional statements can be also used to accomplish conditional sending of notifications by taking advantage of the fact that emails with empty body are never sent. This means that you can put your entire body inside a conditional statement and such notification will be sent out only when the condition is met.

There are two versions of the conditional statement:

$(if) condition $(then) HTML-code-1 $(else) HTML-code-2 $(endif) OR
$(if) condition $(then) HTML-code-1 $(endif)

The first version will output either HTML-code-1 or HTML-code-2, depending on the condition. The second version only prints code when the condition is true. If it's not true, then nothing is printed.

HTML-code-1 will be output if the condition is true, or else HTML-code-2 can optionally be printed.

Simple conditional tags

In the simple form, the condition can take one of the following forms:
XXX greater than YYY - where XXX and YYY are represented by numbers or dates, e.g. '$(if) $(prop_persons) greater than 1 $(then) Please send us the name of the persons coming with you $(endif)' - this will print the text Please send us.... whenever the number of persons chosen at the time of reservation is more than one.
XXX less than YYY - where XXX and YYY are represented by numbers or dates, e.g. '$(if) $(prop_persons) less than 2 $(then) A single-person surcharge of $20 was added to the price. $(else) Couples and families enjoy a discount at the restaurant... $(endif)' - depending on whether the reservation is for a single person or not, one of these two texts will be printed.
XXX equals YYY - where XXX and YYY can be numbers, dates or any other text, e.g. '$(if) $(language) equals EN $(then) See you soon $(endif)' $(if) $(language) equals IT $(then) A presto! $(endif) - this lets you enter a different text based on the language chosen by client at the time of reservation
XXX does not equal YYY - as above but negated
XXX contains YYY - where both XXX and YYY are texts, e.g. '$(if) $(resource) contains apartment $(then) Looking forward to your visit in our luxorious apartment! $(else) Looking forward to your visit in our lodge $(endif)' - For a site which has both lodges and apartments to rent, this lets you print a different message when the resource name contains the word apartment and another one in other cases (lodges in this example).
XXX does not contain YYY - as above but negated
XXX - this checks if a tag is empty or not - e.g. '$(if) $(prop_I_need_airport_pickup) $(then) We'll be there to pick you up at the airport. Look for a tall guy with our logo printed on the jacket and holding your name! $(endif)' - If a tag is represented by any kind of text (the value is not empty), then the text will be printed. A tag is empty if for example it's an item in the reservation form which has no value. In this example, it's a yes/no value that was not selected.

Advanced conditional tags

There are also advanced condition tags which you can use in case of very complex logic. In most cases you won't need to use these tags so stay with simple conditional tags if you can.


Tag nameMeaning
$(or:expr1,expr2), $(or:expr1, expr2,expr3,...)This tag will return the first expression (condition) which is not empty. If all expressions are empty, this will return an empty string. It's used to implement the logical OR operator.
$(and:expr1,expr2), $(and:expr1, expr2,expr3,...)This tag will return the an empty string if at least one of the expressions are empty. If all are not empty, the last expression will be returned. It's used to implement the logical AND operator.
$(not:expr)This tag will return an empty string if expr is not empty. true will be returned if expression is empty. It's used to implement the logical NOT operator.
$(equals:expr1=expr2), $(equals:expr1=expr2=expr3)This tag will return expr1 if all expressions are equal. Otherwise an empty string will be returned. This is used to check if the expressions have the same value as a part of the other conditional tags (and, or, not)
$(contains:haystack:needle)This tag will return true if haystack contains needle, e.g. $(contains:big joe:joe) will return true
$(compare:expr1=expr2), $(compare:expr1<expr2), $(compare:expr1<=expr2), $(compare:expr1>expr2), $(compare:expr1>=expr2), $(compare:expr1<>exepr2)These tags will return true if the comparison is true or an empty string otherwise. Note that this tag can only compare numerical values. As with the $(equals) tag, this is used as a part of the other conditional tags (and, or, not)

Here's a sample:

$(if) $(or: $(equals:$(weekday_number:$(date)) = 6),
            $(equals:$(weekday_number:$(date)) = 7))
$(then)
Today is a weekend, hurray!!
$(else)
The weekend is coming soon!
$(endif)


Tag playground

You can easily test the tags in the tag playground.
FAQ