Email template tips and tricks
James Webster avatar
Written by James Webster
Updated over a week ago

SheepCRM templates are used for automatic emails and can be used by your team for bulk or one-off emails. The template settings provide you with formatting tools you will recognise - such as Bold, hyperlinks etc.

Templates can also be set up to automatically include data from the contact records - to get a "mail merge" benefit for sharing important data fields and personalising the templates which is covered below.

What are Template Tags used for?

You can personalise the emails using template tags. These allow you to insert data from the database into the email. The most common use is to insert the recipient's first name into the salutation e.g.

Hi {{first_name}},

becomes

Hi James,

Information about the recipient is always available for use in the template. Additional data will depend on the context e.g. a ticket purchase or a membership.

Common Fields

  • {{first_name}} (person only)

  • {{last_name}} (person only)

  • {{address_lines}} (a list on one line)

  • {{address_lines|formatlistwithnewlines}} (one per line)

  • {{locality}}

  • {{region}}

  • {{postal_code}}

  • {{primary_email}} (single)

  • {{email}} (a list of emails)

  • {{telephone}} (a list of phone numbers)

  • {{formatted_name}}

    Other Address fields:

  • {{iso_country}}

  • {{royal_mail_international_zone}}

Tickets

  • {{ticket.buyer}}

  • {{ticket.ticket_id}}

  • {{ticket.ticket_type}}

  • {{ticket.date}}

  • {{ticket.reference}}

  • {{ticket.amount}}

Membership

  • {{member.membership_number}} 

  • {{member.plan_name}} 

  • {{member.plan_public_name}}  

  • {{member.period_date_range}}  eg. 12 months (2019-05-22 - 2020-05-22)

  • {{member.start_date}} 

  • {{member.end_date}} 

  • {{member.amount}}

  • {{member.membership_record_status}}  

  • {{member.auto_renew}} 

  • {{member.admin_contact}} 

  • {{member.plan_cost}} - the base cost excluding any discounts when the member renews

  • {{member.plan_currency}}   - the currency of the membership plan

  • {{member.plan_description}} 

  • {{next_plan_cost}}

  • {{next_plan_currency}}

  • {{next_plan_description}}

  • {{next_plan_joining_fee}}

  • {{next_plan_name}}

  • {{next_plan_public_name}}

    Display linked members seperated by a comma

  • {% for m in member.linked_members%}{{m.display_value}}{{ ", " if not loop.last else "" }}{% endfor %}

Booking

  • {{booking.title}}

  • {{booking.date_range}}

  • {{booking.start_date}}

  • {{booking.start_datetime}}

  • {{booking.end_date}}

  • {{booking.end_datetime}}

  • {{booking.venue_for_display}}

  • {{booking.activity_for_display}}

Booking fields are also available when a ticket is selected

Donation

  • {{donation.amount}}

  • {{donation.appeal.display_value}} / This is the name of the Appeal

  • {{donation.currency}}

  • {{donation.date}}

Group Membership

  • {{group_member.group_name}}

  • {{group_member.status}}

  • {{group_member.role}}

  • {{group_member.group_category}}

What are Link Tags used for?

Link tags generate a URL in the email from a short 'tag'.

Invoices

A PDF invoice link (an invoice URI or a membership URI can be used)

{{invoice.uri|invoice_pdf('download your invoice')}}

or

{{member.uri|invoice_pdf('download your invoice')}}

Link to the invoice within the Sheep App

{{member.uri|invoice('view your invoice')}}

Receipts

{{payment.uri|receipt_pdf('download your receipt')}}


Membership Certificates

{{member.uri|certificate_pdf('download your certificate')}}

 or with custom template

{{member.uri|certificate_pdf('link text goes here','template-certificate-a5')}} 

What are Formatting Controls used for?

Use formatting controls to change the normal output. Date formats are the most common control.

Date Time Format

houselongtime

{{booking.start_datetime|datetimeformat('house_long_time')}}

e.g. Monday, 03 July 2017 16:00

house_long

{{booking.start_datetime|datetimeformat('house_long')}}

e.g. Monday, 03 July 2017

custom

{{booking.start_datetime|datetimeformat('{:%Y-%m-%d}')}}

e.g. 2017-07-03

{{member.end_date|datetimeformat('{:%-d %b %Y}')}} 

3 Jul 2017

The custom formats use the python date format definitions

Adding and subtracting dates.

This isn't really supported but with a bit of work it can be achieved e.g.

The day today is: {{now|datetimeformat('house_long')}} but a week ago it was {{(now|datetimeformat('{:%s}')|integer-(7*60*60*24))|datetimeformat('house_long')}} 

(Convert the date back to seconds, convert from a string to an integer, do the subtraction, convert back to a date string)

List on multiple lines

{{address_lines|formatlistwithnewlines}}

e.g.
Flat 1a
The Cresent
Peak Road

List with commas

{{address_lines|formatlistwithcommas}}

e.g. Flat 1a, The Cresent, Peak Road

Numbers

{{amount|integer}}  12.345 becomes 12
{{amount|decimal}}  12.345 becomes 12.35

What are Conditional Statements and how do I use them?

Email templates can also handle conditional statements, these can be helpful when the template needs to handle different membership plans, or missing information. These can let you show different content based on whether the conditional statement is met for the particular recipient.

Basic 'if' conditional

To check if the tag exists, you can use {% if tag %}, follow with the content and/or tag, then close the conditional with {% endif %}. The example below will check if the recipient's first_name exists, if so it will display it:

Hello {% if first_name %}{{first_name}}{% endif %}

Output (with first_name):

Hello John

Output (without first_name)

Hello

This can also be done in shorter and more concise code. The above conditional has been condensed into the 'shorthand' conditional below - both methods are viable and both will return the same outcome:

Hello {{ first_name or '' }}

Please note: if you are planning on send out email to organisations, using person only tags will results in errors. If you planning on using person only tags on bulk emails, please add a conditional to check if the tag is defined:

{% if first_name is defined %}{{first_name}}{% endif %}

Advanced 'if/else' conditional

Conditionals can also be created to display a fallback if the condition is not met. This is done by adding a {% else %} block with content to handle if the condition is not met.

{% if first_name %}
Dear {{first_name}},
{% else %}
Dear member,
{% endif %}

Output (with first_name):

Dear John,

Output (without first_name):

Dear member,

This can also be done in shorter and more concise code. The above conditional has been condensed into the 'shorthand' conditional below - both methods are viable and both will return the same outcome:

Dear {{ first_name or 'member' }},

Example Conditional Statements

{% if first_name == 'john' %}{% endif %}

Checks if the first_name tag equals 'john'

 {% if first_name != 'john' %}{% endif %}

Checks if the first_name tag does not equal 'john'

 {% if first_name in ['john', 'mary', 'james'] %}{% endif %}

Checks if the first_name tag matches 'john', 'mary', or 'james'

Advanced

To see all available fields use the following:

__fields__

The output is a list of all fields.

To see all data (fields and values)

__all__

This will show a barely readable view of the data packet.

The __all__ syntax is useful for handling fields with hyphens or other characters not permitted by the template

__all__["externalid_my-field-with-hyphens"] 

Did this answer your question?