1
votes

My objective is to render a Twig Template and send the resulting HTML via API to Mailchimp to be sent out.

My current process:

1) create a Twig-Template email.html.twig.

2) $html = $this->renderView('MyBundle:email.html.twig');

3) sendHtmlViaApi($html);

The issue: I need a URL to contain a Mailchimp Merge Tag String, which has to be *|VARIABLE|*. I do that with {{ path('my_route', {variable : '*|VARIABLE|*'}) }}. The desired result: /myroute/*|VARIABLE|*. The result I get: /myroute/*%7CVARIABLE%7C*.

Already tried and failed methods:

1) using {% autoescape %}

2) |raw

3) Twig Extension with new url_decode Filter from Symfony2 Twig stop escaping path

2
Are you positive that mailchimp does not handle the escaped url? There is a reason for escaping. Generating invalid url's seems strange.Cerad

2 Answers

0
votes

So you want Twig to stop the automatic URL encoding.

You can pass a placeholder with only letters and underscore to path(), so that it won't be escaped. Then you can replace the placeholder with the string Mailchimp expect:

{{ path('my_route', {variable : 'MAILCHIMP_VARIABLE'})|replace({
    'MAILCHIMP_VARIABLE': '*|VARIABLE|*'
}) }}
0
votes

Thanks for your suggestions! In the end it was all my own fault... One of the merge tags was missing on the mailchimp-side setup, so it couldn't replace it with the desired value. Silly me!