EmailService now has Twig render email messages in safe mode.

-- https://craftcms.com/changelog#build2903

I don't think this is really a bug as it's intended behaviour, but this is causing me a pretty big issue because my email layout has code in it like:

{% set contactDetails = craft.globals.getSetByHandle('contactDetails') -%}

But I think safe mode now means that the craft variable isn't actually available. I can pass it in manually when I'm sending non-standard emails with craft()->emails->sendEmail(), but has anyone found a way around this for the built-in ones like the activation/verification emails?


As of Craft 2.6.2916, the email fields are no longer ran through Twig's safe mode.

EmailService no longer has Twig render email messages in safe mode, which was a little heavy-handed and prevented email message templates from accessing global variables and other things.


OK so it's pretty easy to pass additional variables to the email template using the email.onBeforeSendEmail event:

craft()->on('email.onBeforeSendEmail', function(Event $event)
    $event->params['variables']['craft'] = new CraftVariable();

Although I guess there are security reasons for email templates being rendered in safe mode in the first place so I don't know how much of a good idea this is...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.