Buttondown uses a templating language to mix programming code into plain old HTML. By adding logic and variables to your email you can customize your content per-subscriber, or to repeat structures in your email without having to hand code them multiple times.
Buttondown's templating language is built on top of Django.
Variables
Variables allow you to programmatically add text to your email. You may have previously worked with variables in the form of "mail merges".
Variables are wrapped in double curly braces. Here's how this looks:
Like a mail merge, the variable code is replaced with the correct text when an email is sent out. For example, if you wanted to add a personalized greeting to your email, it might look like this:
Buttondown Playground
Loading playground...Check out our article on metadata to learn what's possible!
Filters
Filters are tools that you can use to modify the output of a variable. This uses the same double curly brace syntax, but the variable name is followed by a pipe and the filter you'd like to use.
For example, if you wanted to make sure your email subject line was always capitalized, you could add the capfirst filter, like so:
As Buttondown's templating language is built on Django you can use any of their available filters.
Tags
Tags are bits of code that are added to your HTML content that can do all sorts of things, including logic!
Tags are wrapped in a single curly brace and a percentage sign, and look like this:
The for and if else loops should cover most use cases in Buttondown.
for
If you want to send a weekly digest of all your blog posts, you could iterate over the list of these items with a for loop:
You might want to also be able to access a counter for each iteration. You can do this by using the forloop object. Here's how you could use it to add a number to each blog post:
if else
If you wanted to send your premium subscribers a special message you could use an if/else loop, like this:
You could also use elif (else if) tags to send different messages to your premium subscribers, free subscribers, and non-subscribers. Here's how this would look:
Have a situation that needs something more than a for or if else loop? Fear not! There are lots of other pre-built tags on the Django site.
Template variables
email.absolute_url
email.absolute_url
Loading playground...- The absolute URL of the email you're sending out.
email.urlis an alias foremail.absolute_urland works the same way (useemail.absolute_urlin new templates).
email.is_premium
email.is_premium
Loading playground...- A boolean indicating whether the email is being sent to a premium subscriber.
email.publish_date
email.publish_date
Loading playground...- The raw date time of the email being sent out.
email.secondary_id
email.secondary_id
Loading playground...- The issue number of the email being sent out.
email.subject
email.subject
Loading playground...- The subject of the email you're sending out.
- The subject length is limited to 2000 characters.
manage_subscription_url
manage_subscription_url
Loading playground...- A link that allows subscribers to change the data configured as subscribe form inputs. This requires the Portal to be enabled.
medium
medium
Loading playground...- Either 'email' (for emails) or 'web' (for web views).
premium_subscribe_url
premium_subscribe_url
Loading playground...- A link to prompt existing free subscribers to upgrade. (Only relevant for paid newsletters.) This is the exact same thing as upgrade_url.
random_number
random_number
Loading playground...- A random number between two values for things like A/B testing.
subscribe_form
subscribe_form
Loading playground...- An embedded subscribe form for your newsletter, just like the one that appears at the bottom of your archives.
- This only appears on the web/archive version of your email; it will not appear in the actual emails sent to subscribers.
subscribe_url
subscribe_url
Loading playground...- A generic URL for your subscription page.
subscriber.can_be_upsold
subscriber.can_be_upsold
Loading playground...- Whether or not a subscriber is able to be upsold to a paid subscription.
subscriber.can_view_premium_content
subscriber.can_view_premium_content
Loading playground...- A boolean that is
trueif the subscriber is on a paid plan andfalseif they are not.
subscriber.email
subscriber.email
Loading playground...- Access to the email address for a given subscriber.
subscriber.id
subscriber.id
Loading playground...- The unique ID for a given subscriber.
subscriber.metadata
subscriber.metadata
Loading playground...- Access to the metadata for a given subscriber.
subscriber.subscriber_type
subscriber.subscriber_type
Loading playground...- Access to the subscriber type (premium, regular, etc) for a given subscriber.
subscriber.tags
subscriber.tags
Loading playground...- Access to the tag names of a given subscriber.
unsubscribe_url
unsubscribe_url
Loading playground...- A personalized URL for the given subscriber to unsubscribe with.
upgrade_url
upgrade_url
Loading playground...- A link to prompt existing free subscribers to upgrade. (Only relevant for paid newsletters.)