campaignmonitor / createsend-php

A PHP library for the Campaign Monitor API
http://campaignmonitor.github.io/createsend-php
Other
285 stars 106 forks source link

IF/ELSEIF with template variables #76

Closed eusonlito closed 6 years ago

eusonlito commented 6 years ago

I'm sending email campaigns from RSS feed and I need to check the priority of each post to show into template.

I'm sending only one post on each mail.

My backend code is:

$this->apiCampaigns()->create_from_template($this->config['client_id'], [
    'Name' => '['.date('d/m/Y H:i').'] '.$feed->title,
    'Subject' => $feed->title,
    'FromName' => config('mail.from.name'),
    'FromEmail' => config('mail.from.address'),
    'ReplyTo' => config('mail.from.address'),
    'SegmentIDs' => [$this->segment()],
    'TemplateID' => $this->template(),
    'TemplateContent' => [
        'priority' => $feed->priority,

        'Singlelines' => [
            [
                'Content' => $feed->title
            ],
            [
                'Content' => $feed->description
            ],
            [
                'Content' => 'AMPLIAR INFORMACIÓN',
                'Href' => $feed->link
            ]
        ]
    ]
]);

My template is:

[if:priority="baja"]

<h3>Importancia baja</h3>
<img class="u-mx-auto" alt="Indicador alerta baja" width="220" src="images/indicador_alerta_baja.png">

[elseif:priority="media"]

<h3>Importancia media</h3>
<img class="u-mx-auto" alt="Indicador alerta media" width="220" src="images/indicador_alerta_media.png">

[elseif:priority="alta"]

<h3>Importancia alta</h3>
<img class="u-mx-auto" alt="Indicador alerta alta" width="220" src="images/indicador_alerta_alta.png">

[endif]

But all code works fine except priority. Never show any value.

How can I pass priority value to template?

Thanks!

mjwills commented 6 years ago

I believe Dynamic Content (IF etc) are based on the subscriber's custom fields. https://www.campaignmonitor.com/create/dynamic-content/#IF-Equals has some details.

eusonlito commented 6 years ago

@mjwills I also think that, but then, can I add some string value to priority? As

<h3>Importancia [priority]</h3>
<img class="u-mx-auto" alt="Indicador alerta alta" width="220" src="images/indicador_alerta_[priority].png">

(It's only an idea).