Email shouldn’t be boring: How to create a horoscope generator within an email

The best way to keep your emails from feeling blah is to write interesting, relatable content that personally addresses the thoughts and feelings of your audience. But when you look at the broader internet, sites have all sorts of other surprising and delightful little widgets that add that little bit of magic to move an audience from liking content to loving it.

A lot of people think you can’t replicate those bits of delight in an email; but at AWeber we know that’s not true. We’ve built our templating language in a way that lets you create all sorts of exciting dynamic and personalized elements for your audience.


I’m going to show you how to create a horoscope that will be randomly generated for each of your subscribers whenever you send them an email. You don’t have to be a programmer to learn how to do this, it’s just a few simple lines of Jinja (that’s the templating language we use in AWeber).

What are we making today?

We’re going to create a horoscope for your subscribers that has two dynamic sections so your subscribers will get a randomly generated prediction with every email you include this in.

The two sections are:

  • A section where we tell someone what type of day it’s going to be (good, bad, strange, etc).
  • The end of the horoscope where we tell them something they should avoid doing today.

Here’s what it’s going to look like:

What the Jinja-coded horoscope generator will look like in an email.

Setting up your horoscope generator

To start, pull a text element into your message (you can do this as an existing text element if you want, I just prefer to have it in its own element to make it easier to manage).

Now open Source view in the text element.

How to use AWeber's text element so you can add custom Jinja code to your emails.

Write or paste the following block of text into the Source view window and hit “ok”.

{% set horoscopeDayType = [

  “A good day”,

  “A bad day”,

  “A grand old time”,

]%}

{% set horoscopeActivity = [

  “feeding the ducks”,

  “finally finishing that time machine you’ve been working on”,

  “writing too many letters to too many editors”,

]%}

<p>Today is going to be {{ horoscopeDayType | random }} as long as you avoid {{ horoscopeActivity | random }}.</p>

When you click to preview your message, you’ll see your random horoscope. When you switch back and forth between edit and preview mode you should get a re-generated horoscope.

How does this Jinja horoscope generator work?

Let’s look at each of the sections of code we dropped in.

{% set horoscopeDayType = [

  “A good day”,

  “A bad day”,

  “A grand old time”,

]%}

This is an array, or collection, of phrases that will fill in the first section of the sentence:

“Today is going to be {{ horoscopeDayType | random }}.”

If you want to add new items that might get pulled, just add another line:

  • Make sure that your new text is wrapped in quotation marks
  • Make sure each line ends with a comma after the closing quote
{% set horoscopeActivity = [

  “feeding the ducks”,

  “finally finishing that time machine you’ve been working on”,

  “writing too many letters to too many editors”,

]%}

This is the array that is filled with items that randomly get pulled into the second part of the sentence:

as long as you avoid {{ horoscopeActivity | random }}.”

Finally, we have the bit of code that actually defines what shows for your subscribers.

<p>Today is going to be {{ horoscopeDayType | random }} as long as you avoid {{ horoscopeActivity | random }}.</p>

AWeber uses the Jinja “random” filter to randomly select one of the items in the “horoscopeDayType” array for each of your subscribers.

How to use Jinja's random filter to make text rotate within an email message.

That’s all there is to it! Now you know how to make an array of text and randomly show one of the items from the array in your message. And you’ve put those principles to use to build a dynamic horoscope generator.

These same principles can be used to add weekly quotes, your favorite recommended links, random product recommendations, or to introduce some variety into your email introduction.

In a future tutorial, I’ll show you how to make even more dynamic horoscopes that use randomly selected sentence structures to add more variety to the types of horoscopes your audience might get.