Mad Mimi

Conditional blocks

Note: This feature is deprecated and will be removed. If you need it, please let us know your use-case and we’ll make sure we add support for it.

Introduction

Conditional blocks allow you to have HTML elements be removed (or retained) in your email based on values in the audience member’s columns.

All conditional blocks require at least data-mimi-condition, data-mimi-column and data-mimi-value attributes. Additional attributes can be included to change the default behavior which is to remove the block if the condition fails, for example:

<p data-mimi-condition='contains' data-mimi-column='job' data-mimi-value='accountant'>
  You are an accountant.
</p>

This block will only show if the audience member has a custom column called ‘job’ and the value of that
column is ‘accountant’, in all other cases it will be removed. Even when the block is not removed all the data-mimi-* attributes will be removed so the final rendered email will only have:

<p>
  You are an accountant
</p>

The behavior of the condition can be reversed by including a data-mimi-on-failure attribute with a value
of ‘retain’. For example:

<p data-mimi-condition='contains' data-mimi-column='job' data-mimi-value='accountant' data-mimi-on-
failure='retain'>
  You are NOT an accountant.
</p>

This block will be retained in the case where the audience member either does not have a ‘job’ column at all or the value in the ‘job’ column does not contain the word ‘accountant’.

Conditions

There are currently five conditions available and of these ‘contains’ is the simplest.

Contains

The contains condition does a simple string search to see if the value in the column contains, anywhere, the value supplied. For example:
● ‘accountant,book-keeper’ contains ‘accountant’ but also contains ‘count’, ‘ant’ and even ‘a’, as well
as ‘book’, ‘keeper’ and so on.
● ‘2, 5, 9, 10, 36’ contains ‘10’ but also contains ‘1’ See the examples above for contains usage.

List_contains

List_contains treats the value in the column as a comma separated list. For example:
● ‘accountant,book-keeper’ list_contains ‘accountant’ and ‘book-keeper’ but not ‘count’, ‘book’ or ‘keeper’
● ‘2, 5, 9, 10, 36’ list_contains ‘10’ but not ‘1’. The entire list item must match.

List_contains is useful for comparing to a list of id’s such as categories, or any list of unique items.

<div data-mimi-condition='list_contains' data-mimi-column='jobs' data-mimi-value='accountant'>
  Check out these exciting deals for accountants.
</div>

The above block would be retained for any audience member that has the value ‘accountant’ in their list of
jobs. So an audience member that has ‘accountant,musician,’ as the value of that column would see it, but one that has ‘book-keeper,farmer’ would not.

Note that spaces are stripped out of the list, so ‘2, 5, 9, 10, 36’ is equivalent to ‘2,5,9,10,36’.

List_contains_any

list_contains_any goes one step further and treats both the column value and the value supplied as a comma separated list. For example:
● ‘accountant,book-keeper’ list_contains_any ‘accountant,financial advisor’ and also ‘tax consultant,book-
keeper’
● ‘2, 5, 9, 10, 36’ list_contains ‘2, 10, 50’ and ‘5, 6, 7, 8’ but not ‘11, 12, 13, 14, 15’

list_contains_any is useful for when you want to show something to everyone who falls into a particular super group. For example:

<div data-mimi-condition='list_contains_any' data-mimi-column='jobs' data-mimi-
value='accountant,book-keeper,tax consultant,financial advisor'>
  Check out these exciting deals for the financially minded.
</div>

The above block would be retained for any audience member that has the value any of the four financial jobs in their list of jobs. So an audience member that has ‘accountant,musician,’ as the value of that column would see it, as would one that has ‘book-keeper,farmer’, but a ‘musician,waiter’ would not.

Retained and Removed

As the conditional blocks are evaluated and retained or removed, a count is kept of the number of blocks
retained or removed for each column. This count can be used in later conditional blocks to, for example,
ensure that an audience member only gets a limited number of special offers or gets at least a certain number of special offers.

<div data-mimi-condition='list_contains_any' data-mimi-column='jobs' data-mimi-
value='accountant,book-keeper,tax consultant,financial advisor'>
  Check out these exciting deals for the financially minded.
</div>
<div data-mimi-condition='retained' data-mimi-column='jobs' data-mimi-value='0'>
  Check out these exciting deals for everyone else
</div>

The block for the financially minded amongst your audience would be retained for any audience
member that has the value any of the four financial jobs in their list of jobs. So an audience member
that has ‘accountant,musician,’ as the value of that column would see it, as would one that has ‘book-
keeper,farmer’, but a ‘musician,waiter’ would not.

However, the ‘musician,waiter’ would see the second block for everyone else because the retained count on the ‘jobs’ column is 0 for him. The same result can be achieved by using ‘removed’

<div data-mimi-condition='list_contains_any' data-mimi-column='jobs' data-mimi-
value='accountant,book-keeper,tax consultant,financial advisor'>
  Check out these exciting deals for the financially minded.
</div>
<div data-mimi-condition='removed' data-mimi-column='jobs' data-mimi-value='1'>
  Check out these exciting deals for everyone else
</div>

The ‘musician,waiter’ would still see the second block for everyone else because the first block was removed and removed count on the ‘jobs’ column is 1 for him. There are cases where one or the other count will make more sense.

It is possible to not count a particular retention or removal by including the data-mimi-count attribute with a
false value. This is useful for headings using the list_contains_any condition containing child blocks using list_contains. For example:

<div data-mimi-condition='list_contains_any' data-mimi-column='jobs' data-mimi-
value='accountant,book-keeper,tax consultant,financial advisor' data-mimi-count='false'>
  <h1>Financial Services</h1>
  <p data-mimi-condition='list_contains' data-mimi-column='jobs' data-mimi-value='accountant'>
    Check out these exciting deals for accountants
  </p>
  <p data-mimi-condition='retained' data-mimi-column='jobs' data-mimi-value='0'>
    Check out these exciting deals for others in financial services
  </p>
</div>

In the above example, the ‘accountant,musician’ would see the Financial Services heading and the deals for accountants paragraph but not the offer for others in financial services.

More interesting though, the ‘book-keeper,farmer’ would also see the heading and then see the offers for
others. Because the outer div element has data-mimi-count=‘false’ it’s not counted as being retained, and so the retained count on the ‘jobs’ column is 0 for the second offer paragraph.

The ‘musician,waiter’ would not see any of it because even though the retained count would be 0 for the
second offer, the offers are child nodes of the outer div which is entirely removed.

Modifiers

Modifiers change the default behavior of the conditional blocks. In the introduction we saw how ‘data-mimi-on-failure’ can be set to ‘retain’ to keep a block on failure of the condition rather than removing it. There is also a data-mimi-on-success modifier. The on-success modifier always overrides the on-failure modifier, i.e., if you have a data-mimi-on-success attribute, data-mimi-on-failure is ignored.

There are three possible values for the two modifiers: ‘retain’, ‘remove’, and the special value ‘style’. The
default behavior for data-mimi-on-failure is ‘remove’, while the default behavior for on-success is ‘retain’.
Setting those to the opposite value respectively will reverse the behavior.

The style option allows you to conditionally add CSS styling if the condition succeeds. This is useful, for
example, to highlight the first special offer a member receives. The actual CSS is supplied in another attribute: data-mimi-style and the CSS is added onto any other style that the element already has.

<div data-mimi-condition='list_contains_any' data-mimi-column='jobs' data-mimi-
value='accountant,book-keeper,tax consultant,financial advisor' data-mimi-count='false'>
  <h1>Financial Services</h1>
  <p data-mimi-condition='list_contains' data-mimi-column='jobs' data-mimi-value='accountant'>
    <span data-mimi-condition='retained' data-mimi-column='jobs' data-mimi-value='1'
data-mimi-on-success='style' data-mimi-style='background-color:red;'>
      Check out these exciting deals for accountants
    </span>
  </p>
  <p>
    <span data-mimi-condition='retained' data-mimi-column='jobs' data-mimi-value='0'
data-mimi-on-success='style' data-mimi-style='background-color:red;'>
      Check out these exciting deals for others in financial services
    </span>
  </p>
</div>

In the above example all financially minded people will see the second offer. However, the accountants
will also see the first one. For accountants the first offer will have a red background, and the second one
is displayed normally. For everyone else, the first offer is not visible and the second offer gets the red
background.

Plain text

It is important to not include a plain text version of your mailing when using conditional blocks. When the email is rendered the plain text will be inferred from the HTML after the conditional blocks have been applied. If you supply a plain text version that will be used instead.