1

I added tomodomo/twig-pluralize-extension to my project composer, loaded with a custom module like that :

if (Craft::$app->request->getIsSiteRequest()) {
    // Add in our Twig extension
    $pluralize = new \Tomodomo\Twig\Pluralize;
    Craft::$app->view->registerTwigExtension($pluralize);
}

I use this to pluralize some string in my templates and email templates. When I check the url to my email template, everything work fine but the email didn’t send out because of "unknown function pluralize".

I have another custom module (to handle something else in my emails) and this part work fine.

Do I need to register/declare TwigExtensions with another method to get them work in emails ?

Note:

  1. The only error related to my emails in the logs is about pluralize function missing.

  2. Everything work fine if I don’t use |pluralize

1

All you should need to do is remove this condition check:

if (Craft::$app->request->getIsSiteRequest()) {

You are only registering the twig extension for front end (site) requests, but emails can be triggered both on a cart complete front end (site) requests AND a back-end (CP) order status changes.

| improve this answer | |
  • May I use a double condition check ? Like so : if (Craft::$app->request->getIsSiteRequest() || Craft::$app->getRequest()->getIsCpRequest()) { The email using |pluralize is sent from my other custom module, not from a Order Status Change. – Maxime Lafrenière Feb 4 '19 at 13:49
1

Replace my if condition by

if ( Craft::$app->request->getIsSiteRequest() || Craft::$app->getRequest()->getIsCpRequest() ) {

Thanks to Luke Holder for pushing in the right direction!

| improve this answer | |

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.