Customizing Content and Messages

You can insert Snippets of code into your web page content and email messages wherever you want user specific or conditional text. This can be done anywhere you provide user facing text such as when you enter your page content, or when you compose the subject and body of confirmation or tell-a-friend emails, or when you write a mailing. To facilitate this, we provide click-to-insert template tags, or Snippets.

The available Snippets vary somewhat depending on what you're doing - different Snippets may be available to insert in a mailing versus a page or a confirmation email.

You can also use the merge files and merge queries features in Mailings to create your own Snippets, see Merge files and Merge queries.

Overview

Snippets are most often used to pull a value for a specific user from your database and either insert it in some user-facing text or use it as a trigger for displaying text conditionally.

Snippets are also available for:

  • Inserting universal values like date
  • Including user- or location-specific data not provided by default in ActionKit but that you upload using Merge files or query with Merge queries
  • Changing how link display and tracking works in your mailings
  • Including action and target-specific info in an e-delivery

Basic Snippets will look something like this: {{ user.zip }}. The first part tells you what object the snippet relates to (e.g. user for info specific to a user like name, zip or phone; order for info related to a donation). The second part sometimes corresponds directly to a field in the database (e.g. zip in the core_user table). Sometimes it's a value that's calculated based on a field in the database. For example {{ targets.their }} displays his, hers, or theirs depending on the gender (pronoun) values for the relevant targets.

Some Snippets have built-in safeties so you don't accidentally include a blank in the display to a user:

  • Default values: For some Snippets, such as First name, a default value is defined within quotes, "Friend". The default value displays if the user has a blank in the field. You can change any value contained within quote marks in a snippet. You can also get rid of the default, although this isn't recommended unless you know that every user has a value in the relevant field.
  • Requires value: Some Snippets don't have a default and should only be used if the user has a value for the snippet. For example, the "highest previous" snippet only returns a value for donors. If the snippet includes requires value ActionKit will skip any users who don't have a value, rather than showing a blank for the snippet. This is only relevant for mailings. You can see information about any users who are skipped in the Mailing report.
  • Landing Page: When using Snippets in mailings, some Snippets can only be used if ActionKit knows what page to use to determine the value. As an example, the tag Suggest Ask requires that you also provide a url to the page where the algorithm for computing the ask price is defined.

Snippets use the template tag functionality included with Django, the platform on which ActionKit is built. You can use o ther Django tags to do things like change how a number is displayed or capitalize the first letter in a word. Read more here.

Snippet Categories Available By Usage

Snippet Categories Pages Mailings
Page content Immediate Delivery Confirmation Tell-a-Friend
Users X X X X X
Donation Under Thank you text   X X  
Recurring donations Under Thank you text / Donation   X X  
Donation history     X X Under Donations
Page Targets Under Call pages1 X     X
Whipcount Pages X   Under Whipcount action Under Whipcount action  
Other Info 2 X   Under Action & other info Under Action & other info X
Page Under Thank you text   X X  
Events         X
Advanced Examples 3 X X     X
Links         X
E-delivery         X

Note

Page Targets - Target-related Snippets available under Call Pages only work on call pages, not petition or letter pages.

Other Info - Date snippet in all categories, plus an action field snippet in the after action categories.

Advanced Examples - The Advanced Examples for Mailings and Pages are slightly different.

Pages Snippets

The Snippets available for use with Pages are dependent on the context.

Page Text Content

The following categories of Snippets are available for creating page content:

Users

Name Snippet
First name {{ user.first_name|default:"Friend" }}
User city {{ user.city|default:"your city" }}
User state abbreviation {{ user.state|default:"your state" }}
User state name {{ user.state_name|default:"your state" }}
User zip {{ user.zip }}
User district {{ user.location.us_district|default: "your district" }}
User country {{ user.country|default:"your home country" }}
User custom field {{ user.custom_fields.favorite_color|default:"your favorite color" }}

Pages With Targets

These Snippets can only be used in the page content for call, petition, letter or whipcount pages that have a target selected.

Name Snippet
Phone numbers {% for target in targets.targets %}
{{ target.title_last }} - {{ target.phone }} {% endfor %}
Local Office numbers {% for target in context.targets.targets %}
{{target.title_full}} {% if target.has_callable_offices %}
{% for ofc in target.local_offices %}
{{ ofc.city }}, {{ofc.state}}: {{ ofc.phone }}
{% endfor %}
{% endif %} {% endfor %}
Local Offices w/checkboxes {{ context.targets.local_offices.as_html }}
Twitter Accounts <ul>
{% for target in context.targets.targets %}
{% if target.twitter %}
<li>{{ target.title_last }} - <a href="{{
target.twitter_link }}">{{ target.twitter }}</a></li>{% endif %}
{% endfor %}
</ul>
Tweet-to-Target Links <ul>
{% for target in context.targets.targets %}
{% if target.twitter %}
<li><a href="https://twitter.com/intent/tweet?text={% filter urlencode %}Dear @{{ target.twitter }}, listen to your constituents.{% endfilter %}">Tweet to {{ target.title_last }} (@{{ target.twitter }})</a>
{% endif %}
{% endfor %}
</ul>
Facebook Accounts <ul>
{% for target in context.targets.targets %}
{% if target.facebook %}
<li>{{ target.title_last }} - <a href="{{
target.facebook_link }}">{{ target.facebook }}</a></li>{% endif %}
{% endfor %}
</ul>
YouTube Accounts <ul>
{% for target in context.targets.targets %}
{% if target.youtube_link %}
<li>{{ target.title_last }} - <a href="{{
target.youtube_link }}">{{ target.youtube|default:target.youtube_id }}</a></li>{% endif %}
{% endfor %}
</ul>
Instagram Accounts <ul>
{% for target in context.targets.targets %}
{% if target.instagram %}
<li>{{ target.title_last }} - <a href="{{
target.instagram_link }}">{{ target.instagram }}</a></li>{% endif %}
{% endfor %}
</ul>
Sen/Rep Smith {{ targets.title_last }}
Senator/Representative Bob Smith {{ targets.title_full }}
Sen./Rep. Bernie Sanders {{ targets.title_informal_full }}
Bernie Sanders {{ targets.informal_full }}
Bob Smith {{ targets.full_name }}
Smith {{ targets.last }}
Him/her/them {{ targets.them }}
He/she/they {{ targets.they }}
His/her/their {{ targets.their }}
His hers/theirs {{ targets.theirs }}
Singular/plural language {{ targets.count|pluralize:"person,people" }}
"s" if plural {{ targets.s }}
Is/are {{ targets.are }}
Isn't/aren't {{ targets.arent }}
Has/have {{ targets.have }}
Hasn't/haven't {{ targets.havent }}
Does/do {{ targets.do }}
Doesn't/don't {{ targets.dont }}
Was/were {{ targets.were }}
Wasn't/weren't {{ context.targets.werent }}
All targets in a sentence {% using targets %} Call {{ them }} and tell {{ them }} {{ they }} {{ are }} rockin'! {% endusing %}
Looping over targets {% for target in context.targets.targets %}
{{ target.us_district }}
{{ target.district_name }}
{{ target.country }}
{{ target.seat }}
{{ target.full_name }}
{{ target.title }}
{{ target.their }}
{{ target.state }}
{{ target.party }}
{{ target.type }}
{{ target.email }}
{{ target.contact_html }}
{{ target.fax }}
{{ target.phone }}
{{ target.long_title }}
{{ target.last }}
{{ target.title_full }}
{{ target.title_last }}
{{ target.first }}
{{ target.gender }}
{{ target.them }}
{{ target.they }}
{{ target.theirs }}
{% if target.twitter %}<a href="{{ target.twitter_link }}">{{ target.twitter }}</a>{% endif %}
{% if target.facebook %}<a href="{{ target.facebook_link }}">{{ target.facebook }}</a>{% endif %}
{% if target.youtube_link %}<a href="{{ target.youtube_link }}">{{ target.youtube|default:target.youtube_id }}</a>{% endif %}
{% if target.instagram %}<a href="{{ target.instagram_link }}">{{ target.instagram }}</a>{% endif %}
{% endfor %}

Whipcount Page

These Snippets can only be used in the page content for whipcount pages.

Name Snippet
Target groups {% for group in target_groups %} {{ group.name }} {{ group.type }} {% endfor %}
Targets by target groups with results {% for group in target_groups %} {{ group.name }} {{ group.type }} {% for target in group %} {{ target.title_last }} is {{ target.stance }}. {{ target.supportive }} supportive calls, {{ target.opposed }} opposed calls, {{ target.undecided }} calls, {{ target.calls }} calls. {% endfor %} {% endfor %}
Target (when request if for a particular target) {{ target.type }}
{{ target.seat }}
{{ target.country }}
{{ target.state }}
{{ target.us_district }}
{{ target.district_name }}
{{ target.title }}
{{ target.long_title }}
{{ target.first }}
{{ target.last }}
{{ target.phone }}
{{ target.fax }}
{{ target.email }}
{{ target.gender }}
{{ target.party }}
{{ target.full_name }}
{{ target.title_last }}
{{ target.title_full }}
{{ target.they }}
{{ target.them }}
{{ target.their }}
{{ target.theirs }}
{{ target. }}
Target status {{ target.stance.view }}
Conditional for "thanks" {% if target.stance.view == "supportive" %}Thank script{% endif %}
Conditional for "spanks" {% if target.stance.view == "opposed" %}Spank script{% endif %}
Conditional for "uncommitted" {% if target.stance.view == "uncommitted" %}Uncommitted script{% endif %}

Thank You Text

Most of these Snippets can only be used by donation type pages. But some of the Snippets under the Page category can be used by all page types.

Name Snippet Page Type
Donation Donation
Date {{ order.created_at|date:"F j, Y" }} Donation
Card (last four digits) {{ order.card_num_last_four }} Donation
Total {{ action.order.total }} or {{ order.total }} Donation
Shipping address  
Address 1 {{ action.order.shipping_address.address1 }} Donation
Address2 {{ action.order.shipping_address.address2 }} Donation
City {{ action.order.shipping_address.city }} Donation
State {{ action.order.shipping_address.state }} Donation
Region {{ action.order.shipping_address.region }} Donation
Postal {{ action.order.shipping_address.postal }} Donation
Zip {{ action.order.shipping_address.zip }} Donation
Plus4 {{ action.order.shipping_address.plus4 }} Donation
Country {{ action.order.shipping_address.country }} Donation
Billing address  
Address 1 {{ order.user_detail.address1 }} Donation
Address 2 {{ order.user_detail.address2 }} Donation
City {{ order.user_detail.city }} Donation
State {{ order.user_detail.state }} Donation
Region {{ order.user_detail.region }} Donation
Zip {{ order.user_detail.zip }} Donation
Plus4 {{ order.user_detail.plus4 }} Donation
Postal {{ order.user_detail.postal }} Donation
Country {{ order.user_detail.country }} Donation
Product Details, list products {% for detail in action.order.order_details %} {{ detail.quantity }} {{ detail.product.name }} - ${{ detail.amount }}
{% endfor %}
Donation
Recurring Donation  
Status {{ orderrecurring.get_status_display }} Donation
Amount ${{ orderrecurring.amount }} Donation
Start {{ orderrecurring.start }} Donation
Total ${{ orderrecurring.payment_total }} Donation
Count {{ orderrecurring.payment_count }} Donation
Last Charge {{ orderrecurring.last_payment_date }} Donation
Next Charge {{ orderrecurring.next_payment_date }} Donation
Card {{ orderrecurring.card_num_last_four }} Donation
Period Display {{ orderrecurring.get_period_display }} Donation
Period {{ orderrecurring.period }} Donation
Page  
Full Page URL {{ page.canonical_url }} All
Page Path (no domain) {{ page.canonical_path }} All
Page Type (Donation, Petition, etc.) {{ page.type }} All
Page Title {{ page.title }} All
Page Name (short name used in URL) {{ page.name }} All

Other Info

Name Snippet
Date {% now "F jS, Y" %}
GeoIP Country Name {{ geoip.country_name }}
GeoIP Country Code {{ geoip.country_code }}
GeoIP City {{ geoip.city }}
GeoIP is in European Union? {{ geoip.is_in_european_union }}
GeoIP is in a GDPR country? (EU + UK at the moment) {{ geoip.is_gdpr_country }}
GeoIP Postal Code {{ geoip.postal_code }}
GeoIP Region {{ geoip.region }}
GeoIP Time Zone {{ geoip.time_zone }}
GeoIP Continent Code {{ geoip.continent_code }}
GeoIP Continent Name {{ geoip.continent_name }}
GeoIP Latitude {{ geoip.latitude }}
GeoIP Longitude {{ geoip.longitude }}

Advanced Examples

Name Snippet
Django template documentation (if/else) https://docs.djangoproject.com/en/3.2/ref/templates/language/
Insert argument from query string {{ args.my_field_name }}
Localize content (if/else) {% if user.state == 'CA' %} California has the largest number of robotic dogs per capita.
{% else %}
Robotic dogs are important in every state.
{% endif %}
Content conditional on user's custom field {% if user.custom_fields.likes_puppies == 'yes' %}woof{% else %}meow{% endif %}

Immediate Delivery Emails

Snippets available here are the same as the Snippets defined for Page text content.

After-Action Redirect URLs

Snippets available here are snippets associated with the user who just took action, and the action just taken.

For example, this includes {{ user.custom_fields.donated_2024 }} or {{ action.order.total }}

Confirmation And Notification Emails

The following categories of code Snippets are available for creating confirmation email messages:

User

Snippets available from here are the same as the Snippets defined for Page text content > Users.

Page

Snippets available from here are the same as the Snippets defined for Page text content > Thank you text > Page.

Donation

Snippets available from here are the same as the Snippets defined for Page text content > Thank you text > Donation.

Recurring Donation

Snippets available from here are the same as the Snippets defined for Page text content > Thank you text > Recurring Donation.

Donation History

Snippets available from here are a subset of the Snippets defined for Mailings > Donations Snippets.

Name Snippet
Highest Previous (one-time donations) {% requires_value donations.highest_previous %}${{ donations.highest_previous }}
Highest Previous (all donations) {% requires_value donations.highest_previous_all %}${{ donations.highest_previous_all }}
Average (one-time donations) {% requires_value donations.average %}${{ donations.average }}
Average (all donations) {% requires_value donations.average_all %}${{ donations.average_all }}
Most Recent (one-time donations) {% requires_value donations.most_recent %}${{ donations.most_recent }}
Most Recent (all donations) {% requires_value donations.most_recent_all %}${{ donations.most_recent_all }}
Most Recent Date (one-time donations) {% requires_value donations.most_recent_date %}{{ donations.most_recent_date }}
Most Recent Date (all donations) {% requires_value donations.most_recent_date_all %}{{ donations.most_recent_date_all }}
Year to Date {% requires_value donations.year_to_date %}${{ donations.year_to_date }}

Whipcount Action

Name Snippet
Called with response You called {{ contacted.target.title_last }}, who is {{ contacted.response }}!

Action And Other Info

Name Snippet
Custom action field {{ action.custom_fields.example }}
Date {% now "F jS, Y" %}

Confirmation Email Snippets for Pages with Targets

The available snippets for confirmation emails on pages with targets are similar to those available above, but note that they are accessed slightly differently:

Name Snippet
Phone numbers {% for target in action.targeted.all %} {{ target.title_last }} - {{ target.phone }} {% endfor %}
Twitter Accounts <ul> {% for target in action.targeted.all %} {% if target.twitter %} <li>{{ target.title_last }} - <a href="{{ target.twitter_link }}">{{ target.twitter }}</a> {% endif %} {% endfor %} </ul>
Tweet-to-Target Links <ul>
{% for target in action.targeted.all %}
{% if target.twitter %}
{% concatenate "Dear @" target.twitter ", listen to your constituents." as tweet %}
<li><a href="https://twitter.com/intent/tweet?text={{ tweet|urlencode }}">Tweet to {{ target.title_last }} (@{{ target.twitter }})</a>
{% endif %}
{% endfor %}
</ul>
Facebook Accounts <ul> {% for target in action.targeted.all %} {% if target.facebook %} <li>{{ target.title_last }} - <a href="{{ target.facebook_link }}">{{ target.facebook }}</a> {% endif %} {% endfor %} </ul>
YouTube Accounts <ul> {% for target in action.targeted.all %} {% if target.youtube_link %} <li>{{ target.title_last }} - <a href="{{ target.youtube_link }}">{{ target.youtube|default:target.youtube_id }}</a> {% endif %} {% endfor %} </ul>
Instagram Accounts <ul> {% for target in action.targeted.all %} {% if target.instagram %} <li>{{ target.title_last }} - <a href="{{ target.instagram_link }}">{{ target.instagram }}</a> {% endif %} {% endfor %} </ul>
Singular/plural language {{ action.targeted.count|pluralize:"person,people" }}
"s" if plural {{ action.targeted.count|pluralize:",s" }}
Is/are {{ action.targeted.count|pluralize:"is,are" }}
Isn't/aren't {{ action.targeted.count|pluralize:"isn't,aren't" }}
Has/have {{ action.targeted.count|pluralize:"has,have" }}
Hasn't/haven't {{ action.targeted.count|pluralize:"hasn't,haven't" }}
Does/do {{ action.targeted.count|pluralize:"does,do" }}
Doesn't/don't {{ action.targeted.count|pluralize:"doesn't,don't" }}
Was/were {{ action.targeted.count|pluralize:"was,were" }}
Wasn't/weren't {{ action.targeted.count|pluralize:"wasn't,weren't" }}
All targets in a sentence {% using action.targeted.all %} Call {{ them }} and tell {{ them }} {{ they }} {{ are }} rockin'! {% endusing %}
Looping over targets {% for target in action.targeted.all %} {{ target.us_district }} {{ target.district_name }} {{ target.country }} {{ target.seat }} {{ target.full_name }} {{ target.title }} {{ target.state }} {{ target.party }} {{ target.type }} {{ target.email }} {{ target.fax }} {{ target.phone }} {{ target.long_title }} {{ target.last }} {{ target.title_full }} {{ target.title_last }} {{ target.first }} {{ target.gender }} {{ target.them }} {{ target.they }} {{ target.their }} {{ target.theirs }} {% if target.twitter %}<a href="{{ target.twitter_link }}">{{ target.twitter }}</a>{% endif %}<br> {% if target.facebook %}<a href="{{ target.facebook_link }}">{{ target.facebook }}</a>{% endif %}<br> {% if target.youtube_link %}<a href="{{ target.youtube_link }}">{{ target.youtube|default:target.youtube_id }}</a>{% endif %}<br> {% if target.instagram %}<a href="{{ target.instagram_link }}">{{ target.instagram }}</a>{% endif %}<br> {% endfor %}

Events

These Snippets only work with event pages.

Name Snippet
Venue {{ action.event.venue }}
Address1 {{ action.event.address1 }}
City {{ action.event.city }}
Region {{ action.event.region }}
Postal {{ action.event.postal }}
Start Date {{ action.event.starts_at_dt|date:"l, F j" }}
Starting Hour {{ action.event.starts_at_dt|date:"f A" }}

Tell-a-friend Messages

Snippets available for Tell-a-friend composition are the same as the ones defined for Confirmation and notification emails.

Mailings Snippets

Snippets are organized into several categories:

User Snippets

All of the code Snippets in this category contain user fields for customizing your message. Most of the values are in the core_user table.

The User custom field tag inserts the value for any custom user field you've already created. Read more about custom user fields at custom user fields. You will have to edit the snippet to specify the field name and default value.

The User zip snippet does not contain a default value.

Snippets available for the Users category in mailings are the same as the ones defined for Pages > Users.

Landing Pages Snippets

The snippets in this category are used to insert the content from your Petition, Letter, Call, and other types of pages verbatim into your mailing.

Not all content types are available on all types of pages; see CMS Tables for reference.

Name Snippet
Thank you text {% include_tmpl landing_page_form.thank_you_text %}
Statement Lead-in {% include_tmpl landing_page_form.statement_leadin %}
Statement Text {% include_tmpl landing_page_form.statement_text %}
Letter Text {% include_tmpl landing_page_form.letter_text %}
About Text {% include_tmpl landing_page_form.about_text %}
Introduction Text {% include_tmpl landing_page_form.introduction_text %}
Script Text {% include_tmpl landing_page_form.script_text %}
Survey Question Text {% include_tmpl landing_page_form.survey_question_text %}
Ground Rules {% include_tmpl landing_page_form.ground_rules %}
Volunteer Text {% include_tmpl landing_page_form.volunteer_text %}
Host Requirements {% include_tmpl landing_page_form.host_requirements %}
Host Text {% include_tmpl landing_page_form.host_text %}
Tools Text {% include_tmpl landing_page_form.tools_text %}
Tools Sidebar {% include_tmpl landing_page_form.tools_sidebar %}
Search Page Text {% include_tmpl landing_page_form.search_page_text %}
Signup Text {% include_tmpl landing_page_form.signup_text %}
Talking Points (LTE) {% include_tmpl landing_page_form.talking_points %}
Writing Tips (LTE) {% include_tmpl landing_page_form.writing_tips %}
Ask Text (Donations) {% include_tmpl landing_page_form.ask_text %}
Please Stay Text (Recurring Cancel) {% include_tmpl landing_page_form.please_stay_text %}
Update Card Text (Recurring Update) {% include_tmpl landing_page_form.update_card_text %}

Warning

Be sure to carefully test these snippets to ensure that your content is correctly reflected in your mailing. Some snippets that are available to your page are not available to your mailings, and won't show up -- which could result in awkward phrasing.

Donations Snippets

Donation Snippets do not include default values. If you target non-donors with an email that has a donation snippet, ActionKit will skip users for whom the mailing would show a blank where the tag is. It's best to target only donors or use a conditional that only includes the relevant sentence if the user is a donor. It's also a good idea to view several proofs when using these tags since the donors are especially valuable to you.

Donation snippet calculations are standardized to match donation stats on the individual user record. Donations are complicated and they've changed over to time to account for various scenarios. The donation stats on the individual user record include only completed donations, include imported donations, exclude donations of $0 (like free product orders), and exclude any payments (first or later) toward a recurring donation profile for the one-time donation calculation and include them for recurring. These Snippets use all the same logic.

You can view the SQL used for the user stats.

The Suggested Ask snippet requires an algorithm for computing the ask value. You specify the algorithm by selecting the page that contains the algorithm in the Landing Page dropdown. Read more in Suggested Ask Rules.

Snippets that include only one-time donations are followed by (single). Those with (total) include one-time and recurring donations.

When using the recurring Snippets, if you have donors with more than one active recurring commitment, the tags will only reference the first recurring donation profile.

Name Snippet
Highest Previous (single) {% requires_value donations.highest_previous %}${{ donations.highest_previous }}
Highest Previous (single or recurring) {% requires_value donations.highest_previous_all %}${{ donations.highest_previous_all }}
Average (single) {% requires_value donations.average %}${{ donations.average }}
Average (single or recurring) {% requires_value donations.average_all %}${{ donations.average_all }}
Most Recent (single) {% requires_value donations.most_recent %}${{ donations.most_recent }}
Most Recent Date (single) {% requires_value donations.most_recent_date %}{{ donations.most_recent_date }}
Most Recent (single or recurring) donation {% requires_value donations.most_recent_all %}{{ donations.most_recent_all }}
Most Recent Date of (single or recurring) donation {% requires_value donations.most_recent_date_all %}{{ donations.most_recent_date_all }}
Year to Date (total) {% requires_value donations.year_to_date %}${{ donations.year_to_date }}
Previous Year (total) {% requires_value donations.previous_year %}${{ donations.previous_year }}
Suggested Ask ${{ suggested_ask }}
Recurring Amount {% requires_value donations.recurring_amount %}${{ donations.recurring_amount }}
Recurring Start Date {% requires_value donations.recurring_start_date %}{{ donations.recurring_start_date }}
Recurring Original Amount {% requires_value donations.recurring_original_amount %}${{ donations.recurring_original_amount }}
Recurring Total {% requires_value donations.recurring_total %}${{ donations.recurring_total }}
Recurring Last Charge {% requires_value donations.recurring_last_charge %}{{ donations.recurring_last_charge }}
Recurring Last Amount {% requires_value donations.recurring_last_amount %}${{ donations.recurring_last_amount }}
Recurring Next Charge {% requires_value donations.recurring_next_charge %}{{ donations.recurring_next_charge }}
Recurring Period {% requires_value donations.recurring_period %}{{ donations.recurring_period }}
Most recent transaction from a recurring donation {% requires_value donations.most_recent_recurring %}{{ donations.most_recent_recurring.amount }}
Loop over the transactions for all of a User's Recurring Donations {% for orderrecurring in donations.all_recurring %}{{ orderrecurring.amount }}{% endfor %}
Currency for the most recent recurring donation {% requires_value donations.recurring_currency %}{{ donations.recurring_currency }}
Recurring Card's Last Digits {% requires_value donations.recurring_card_last_four %}{{ donations.recurring_card_last_four }}
Recurring is ACH Direct Debit {% if donations.recurring_is_ach %}...{% endif %}

If you want to display some text in a mailing that's only visible to donors, you can also use ActionKit's donation snippets with the Django {% if %} syntax to check whether a value for the snippet exists, and then use that logic to display your message.

For example:

{% if donations.highest_previous_all %}
    P.S. Thanks for being one of our most wonderful donors!
{% endif %}

This message will only show for donors.

Events Snippets

Events Snippets include samples for recruiting attendees and reminding hosts and attendees about their upcoming event.

More than most snippets, these sometimes require you to set up targeting or landing pages before they work. See the Event mailings section for the necessary setup for recruits and reminders.

For more control over precisely which events are shown and how, see withevents and the events variable in the tags reference.

Page Targets Snippets

Target Snippets only apply when you're asking users to take action on a call, whipcount, letter, or petition page. If you use these Snippets, you must also select the page that identifies your targets from the Landing Page dropdown. For example, if the action you're asking users to take targets Senators, ActionKit will know from the page you select from Landing Page to insert Senators not Representatives.

Whipcount pages only: You can use the congress info Snippets for mailings related to whipcount pages but remember that whipcount pages display all targets (whether or not the user lives in-district).

To use these Snippets in mailings that target constituents and non-constituents, you have to remove the {% requires_value targets.count %} and use conditional logic to show non-constituents something useful:

{% if targets.count %}
<div> Call: <ul>{% for target in targets.targets %}
<li>{{ target.title_last }} - {{ target.phone }} {% endfor %}</li> </ul> </div>
{% else %}
<div>Not a constituent? Call anyway!</div>
{% endif %}
<p> LINK TO YOUR WHIPCOUNT PAGE</p>
Name Snippet
Phone numbers {% requires_value targets.count %} {% for target in targets.targets %} {{ target.title_last }} - {{ target.phone }} {% endfor %}
Local Office numbers {% requires_value targets.count %} {% for target in targets.targets %} {{ target.title_full }} {% if target.has_callable_offices %} {% for ofc in target.local_offices %} {{ ofc.city }}, {{ ofc.state}}: {{ ofc.phone }} <br /> {% endfor %} {% endif %} {% endfor %}
Twitter Accounts <ul> {% for target in targets.targets %} {% if target.twitter %} <li>{{ target.title_last }} - <a href="{{ target.twitter_link }}">{{ target.twitter }}</a> {% endif %} {% endfor %} </ul>
Tweet-to-Target Links <ul>
{% for target in targets.targets %}
{% if target.twitter %}
{% concatenate "Dear @" target.twitter ", listen to your constituents." as tweet %}
<li><a href="https://twitter.com/intent/tweet?text={{ tweet|urlencode }}">Tweet to {{ target.title_last }} (@{{ target.twitter }})</a>
{% endif %}
{% endfor %}
</ul>
Facebook Accounts <ul> {% for target in targets.targets %} {% if target.facebook %} <li>{{ target.title_last }} - <a href="{{ target.facebook_link }}">{{ target.facebook }}</a> {% endif %} {% endfor %} </ul>
YouTube Accounts <ul> {% for target in targets.targets %} {% if target.youtube_link %} <li>{{ target.title_last }} - <a href="{{ target.youtube_link }}">{{ target.youtube|default:target.youtube_id }}</a> {% endif %} {% endfor %} </ul>
Instagram Accounts <ul> {% for target in targets.targets %} {% if target.instagram %} <li>{{ target.title_last }} - <a href="{{ target.instagram_link }}">{{ target.instagram }}</a> {% endif %} {% endfor %} </ul>
Sen/Rep Smith {% requires_value targets.title_last %}{{ targets.title_last }}
Senator/Representative Bob Smith {% requires_value targets.title_full %}{{ targets.title_full }}
Bob Smith {% requires_value targets.full_name %}{{ targets.full_name }}
Smith {% requires_value targets.last %}{{ targets.last }}
Him/her/them {% requires_value targets.count %}{{ targets.them }}
He/she/they {% requires_value targets.they %}{{ targets.they }}
His/her/their {% requires_value targets.their %}{{ targets.their }}
His hers/theirs {% requires_value targets.theirs %}{{ targets.theirs }}
Singular/plural language {% requires_value targets.count %}{{ targets.count|pluralize:"person,people" }}
"s" if plural {% requires_value targets.s %}{{ targets.s }}
Is/are {% requires_value targets.are %}{{ targets.are }}
Isn't/aren't {% requires_value targets.arent %}{{ targets.arent }}
Has/have {% requires_value targets.have %}{{ targets.have }}
Hasn't/haven't {% requires_value targets.havent %}{{ targets.havent }}
Does/do {% requires_value targets.do %}{{ targets.do }}
Doesn't/don't {% requires_value targets.dont %}{{ targets.dont }}
Was/were {% requires_value targets.were %}{{ targets.were }}
Wasn't/weren't {% requires_value targets.werent %}{{ targets.werent }}
All targets in a sentence {% requires_value targets.count %}{% using targets %} Call {{ them }} and tell {{ them }} {{ they }} {{ are }} rockin'! {% endusing %}
Looping over targets {% requires_value targets.targets %} {% for target in targets.targets %} {{ target.us_district }} {{ target.district_name }} {{ target.country }} {{ target.seat }} {{ target.full_name }} {{ target.title }} {{ target.their }} {{ target.state }} {{ target.party }} {{ target.type }} {{ target.email }} {{ target.contact_html }} {{ target.fax }} {{ target.phone }} {{ target.long_title }} {{ target.last }} {{ target.title_full }} {{ target.title_last }} {{ target.first }} {{ target.gender }} {{ target.them }} {{ target.they }} {{ target.theirs }} {% if target.twitter %}<a href="{{ target.twitter_link }}">{{ target.twitter }}</a>{% endif %}<br> {% if target.facebook %}<a href="{{ target.facebook_link }}">{{ target.facebook }}</a>{% endif %}<br> {% if target.youtube_link %}<a href="{{ target.youtube_link }}">{{ target.youtube|default:target.youtube_id }}</a>{% endif %}<br> {% if target.instagram %}<a href="{{ target.instagram_link }}">{{ target.instagram }}</a>{% endif %}<br> {% endfor %}

Other Info Snippets

Name Snippet Description
Today's date {% now "F jS, Y" %} Insert the date on which you send the mailing in this format: November 23rd, 2019. For timed sends, this will refer to the date the mailing is generated.
Custom Mailing Fields {{ custom_fields }} Custom Mailing Fields -- get a specific custom field by referencing its name. For example, to get the value of the field "signature", use {{ custom_fields.signature }}.
Mailing ID {{ mailing_id }} Insert the ID of this mailing.
Recurring Schedule ID {{ recurring_schedule_id }} Insert the recurring_schedule.id of a recurring mailing.
Mailing tags {{ mailing_tags }} A JSON-like object containing each of the tags associated with this mailing.
Mailing web viewable {{ mailing_web_viewable }} Whether or not this mailing is web viewable; use with {% if mailing_web_viewable %} ... {% endif %}
Unsubscribe page name {{ unsub_page_name }} The short name of the unsubscribe page associated with this mailing.
Unsubscribe page URL {{ unsub_page_url }} The URL of the unsubscribe page associated with this mailing.
Page name {{ page_name }} The short name of the page (if any) associated with this mailing.
Landing page name {{ landing_page_name }} The short name of the landing page associated with this mailing. Requires a landing page.
Landing page path {{ landing_page_path }} The URL path of the landing page associated with this mailing. Requires a landing page.

Advanced Examples Snippets

You can also use other fields as triggers based on the Snippets in this category. For example, you could replace state in the Localized content snippet with another user field (like city, country, zip or first_name). If your conditional doesn't appear to be working make sure you've got the correct field name. For example user.first_name is right; user.name isn't.

Name Snippet
Localized content (if/else) {% if user.state == 'CA' %} California has the largest number of robotic dogs per capita. {% else %} Robotic dogs are important in every state. {% endif %}
Content conditional on past actions {% if user|actiontaken:"4" %}
Since you're interested in this issue,
{% else %}
Other content {% endif %}
Content conditional on user's tags {% if user|tagged:"climate" %}
Since you're interested in this issue,
{% else %}
Other content {% endif %}
Content conditional on user's custom field {% if user.custom_fields.likes_puppies == 'yes' %}woof{% else %}meow{% endif %}
Detecting when a user is logged in as a staff member {% if request.user.is_authenticated %}

{% block content %}{% endblock %}

{% else %}

Sorry, you aren't a staff user.

{% endif %}

E-delivery Snippets

These Snippets are part of our e-delivery system for petition signatures or letters. To use these, you need to have set up a petition delivery job, the job needs to have at least one target with more than two signatures, and you need to select the relevant page from the Landing Page dropdown on this screen.

The Staffer/target name snippet inserts the legislative director's name if you're targeting a federal legislator; otherwise it inserts the target name. You can also insert the target's name using the "Sen. Smith" tag.

Always include the download link as this is the only way the legislative director or target will know where to pick up the signatures.

Name Snippet
Staffer/target name {{ user.name }}
Download link http://docs.actionkit.com/comments/?tcid={{ user.tcid }}
Number of constituents signatures {{ section.signatures.count|intcomma }}
Number of signature nationally {{ job.signatures.count|intcomma }}
Sen. Smith {% requires_value targets.count %}{{ targets.title_last }}
Senator John Smith {% requires_value targets.count %}{{ targets.title_full }}

Merge File Snippets

Once you've uploaded a merge file (with a first column that will match the users you are targeting) and selected it on the Compose screen, the mailing will have Snippets available for including the columns for each user. The merge file Snippets use the prefix "merge" followed by the name of the column: {{ merge.column-name }}. As an example, if you uploaded the following merge file, the available Snippets on the Compose screen are {{ merge.zip }} and {{ merge.paper }}.

If you uploaded a file with the columns 'zip' and 'paper':

zip, paper
10014, New York Post
19130, Philadelphia Inquirer
94965, Marin County Chronicle
60632, Chicago Tribune

You could use the snippet {{ merge.paper }} in the mailing, and the paper that matches the user's zip code would be included. If the user's zip code was not included in the merge file, no value would be displayed. You can use a conditional block ( {% if merge.paper %} ... {% endif %} ) or a default ( {{ merge.paper|default:"your local paper" }} ) to avoid sending confusing messages.

Once you've associated a merge file with your mailing, the Snippets under "Merge Files" will use the actual columns from your uploaded file. The Snippets will includes a {% templatetag openblock %} requires_value %} to skip users without matches in the uploaded file.

To email users without matches, remove the requires_value tags that reference the columns that don't need to match. You should add a default filter or an if block to provide reasonable text for users without matching rows in the uploaded merge file.

Merge Query Snippets

If you write a merge query (with a first column that will match the users you are targeting) and select it on the Compose screen, the mailing will have Snippets available for including the columns for each user. The merge query Snippets use the prefix "query" followed by the name of the column: {{ query.column_name }}. As an example, if you write the following merge query, the available snippets on the Compose screen are {{ query.id }} and {{ query.favorite_color }}.

SELECT ca.user_id AS id, caf.value AS favorite_color
FROM core_action ca
JOIN core_actionfield caf ON (ca.id = caf.parent_id)
WHERE ca.page_id = {{ page_id }}
AND caf.name = 'favorite_color';

You can click to insert the {{ query.favorite_color }} Snippet in the mailing, and the current recipient's value for that custom field from the specified page will be included. The Merge Query Snippets include requires_value so your mailing doesn't display a blank if a targeted recipient doesn't have a value returned by the query. That user is skipped. Read more under failed deliveries.

Alternatively, you can remove requires_value and use a conditional block ( {% if query.favorite_color %} ... {% endif %} ) or a default ( {{ query.favorite_color|default:"ultraviolet" }} ).

Advanced Snippets

Other Values

Other user-specific content may be available, even though we've only created built-in Snippets for the most commonly used fields. For example, you can copy and paste any of the following:

  • /?akid={{ user.token }} - Let's say you want to thank users who take action on a petition page in your email, then ask them to contribute to the same campaign. You want the donation page to recognize the user. Just put the code above at the end of the link in your confirmation email.

  • {{ user.location.us_county }} - Returns the user's county. user.location can be used to create Snippets from core_location data in mailings. Address information is in the core_user table, but some other geographic info like county is in the core_location table.

  • {{ event.public_url }} - Returns a relative url like '/event/my_event_campaign_name/2117'. Add your domain in front for a fully-qualified URL. As an example, this has been used to put a Facebook like button on event attendee pages.

  • {{ event.obj.starts_at }} - Returns an event's starts at datetime.

  • {{ campaign.max_event_size }} - Returns the max event size set for the event campaign in the admin (if one was set). For example, use this to display the max in your event creation template.

  • {{ campaign.all_events_count }} - Returns a count of all events for the campaign which haven't been deleted or cancelled. This matches the events count on the campaign dashboard.

  • {{ campaign.open_events_count }} - Returns a count of open events for the campaign which have been approved and confirmed and haven't been deleted or cancelled. This matches the open count on the campaign dashboard.

  • {{ campaign.signups_count }} - Returns a count of active (i.e. not cancelled) signups for events in the campaign. This matches the signups count on the campaign dashboard.

  • {{ campaign.hosts_count }} - Returns a count of active (i.e. not cancelled) hosts for events in the campaign.

  • {{ campaign.attendees_count }} - Returns a count of active (i.e. not cancelled) attendees for events in the campaign.

  • {{ event.max_attendees }} - Returns the max event size set by the host for their event within a campaign. Could be used on an attendee sign up page. It should also work for true/false statements, as shown in the following code sample:

    {% if event.max_attendees %}
    This event can only hold {{ event.max_attendees }} people.
    {% endif %}
    
  • {{ page.name }} - Returns the page's short name.

  • {{ page.title }} - Returns the page's title.

  • {{ user.stats.donated_amt }} - Returns the total ever donated by the user.

Whipcount Confirmation Email Example

The confirmation email can access the target the user called using the action.called.all snippet.

This returns a list (because the form supports submitting the results of multiple calls), so the snippet should either be used in a list:

{% for contact in action.called.all %}
{{ contact.target.title_last }} is {{ contact.response }}{% endfor %}

Or by accessing the first element in the list:

{% with action.called.all.0 as contact %}
{{ contact.target.title_last }} said {{ contact.response }}!{% endwith %}

Donation Confirmation Email Example

If you're using a standard donation page with monthly and one-time gift options, you can use a conditional tag in your confirmation email or on your thank you page to make your thank you message relevant for both donation types. These aren't click-to-insert Snippets, so you'd need to cut and paste them.

Here are two examples:

{% if action.orderrecurring %}
  Thanks for your recurring donation of ${{ action.orderrecurring.amount }}.
{% else %}
  Thanks for your one-time donation of ${{ action.order.total }}.
{% endif %}

— and —

Thanks for your {% if action.orderrecurring %}recurring
 {% else %}one-time{% endif %}
donation of ${{ action.order.total }}.

Also, you may wish to supply the donor with information about other contributions they've made. You might include a message about ongoing recurring donations.

For example:

{% if user.orderrecurring_set.active %}
  Thank you for your continued support:
{% for profile in user.orderrecurring_set.active %}
  ${{ profile.amount }} monthly
{% endfor %}
{% endif %}

This code will also work on a "thanks" followup page, but does NOT work in a mailing. See below for the equivalent snippet for a mailing.

Recurring Donation Mailing Example

The code for displaying a user's recurring donation information in a mailing is slightly different than in a confirmation mailing or page.

{% if user.recurring_orders.active %}
  Thank you for your continued support:
  {% for profile in user.recurring_orders.active %}
    ${{ profile.amount }} monthly
  {% endfor %}
{% endif %}

Customizing Snippets

You can use template tags and variables on the fly or define globally-available custom snippets to be included along with ActionKit's built-in snippets. The latter can simplify the process of assembling pages and mailings that contain frequently used bits of text and code.

You'll need to have superuser permissions to add or modify custom snippet definitions on the CONFIG screen.

Page content, confirmation emails, and mailing body text are different contexts within ActionKit, meaning different information is made available for each. Snippets must be defined separately for each of these contexts. Many snippets are only appropriate for specific contexts (e.g. a "Dear Friend" greeting is likely to be useful for mailings but not pages). This accounts for many of the variations you see in the built-in snippet menus in these categories.

You create custom snippets using the same approach. The Custom Snippets screen has a box for the three contexts mentioned. Enter a snippet in one section if it should only be available in that context, or copy it into all three sections if it should be available to all of them.

Enter each snippet with a brief title to display in the snippets menu then the code to be inserted when users click the title.

Greeting: Dear {{ user.first_name|default:"Member" }},
Signature: -- Sincerely, Us.

The example above shows two snippets that you might add to the Confirmation Email and Mailing Body boxes. If you want your mailings to default to "Dear Member" when a user does not have a first name in your database, you'd click the Custom header at the top of your snippet box in your mailing, then click the Greeting snippet.

The snippet code can contain any mix of template tags, HTML markup, and other text.

If you've defined custom snippets, they appear at the top of the snippets panel for the relevant context.

Grouping Snippets Into Categories

You can group custom snippets into categories by using a slash in the label, like this:

Greeting/Formal: Esteemed {{ user.first_name|default:"Recipient" }},
Greeting/Casual: Hey {{ user.first_name|default:"Buddy" }},

You can only group snippets one level deep.

Multi-line Snippets

You can create multi-line snippets which include return characters either by ending lines with a backslash or by inserting a \n at the appropriate place, as shown below:

Greeting: {% if user.first_name %}  \
        Dear {{ user.first_name }}, \
    {% else %} \
        Esteemed Recipient, \
    {% endif %}
Signature: -- Sincerely, Us. \n   Your friendly local advocacy group.