How to properly extend emails?

Hello,

I need to add a dynamic code block in email bodies; from the documentation I understand that to do this task I have to code a plugin extending

Code:
MauticCoreBundleEventListenerCommonSubscriber
in a EmailSubscriber class.

So I created my HelloWorldBundle in plugin as available at https://developer.mautic.org/?php#extending-emails, but I can't figure out how to use it in email builder to insert a dynamic code.

Any suggestions, hints or tips areappreciated.
-Alessio

Hello,
I need to add a dynamic code block in email bodies; from the documentation I understand that to do this task I have to code a plugin extending MauticCoreBundleEventListenerCommonSubscriber in a EmailSubscriber class.

So I created my HelloWorldBundle in plugin as available at https://developer.mautic.org/?php#extending-emails, but I can’t figure out how to use it in email builder to insert a dynamic code.

Any suggestions, hints or tips areappreciated.
-Alessio

I’m not quite sure what your dynamic code should do, but an existing subscriber to a builder could be a good start to learn how the current functionality has been done:

https://github.com/mautic/mautic/blob/staging/app/bundles/PageBundle/EventListener/BuilderSubscriber.php

Thanks escopecz,
I got it as a basic style.

Anyway, I am trying to get prettier messages. It would be very nice if mails could accept a sort of templating logic (like twig), since this setup forces me to assemble and embed HTML within EmailSubscriber class from plugin bundle.

Looking for any suggestion about; planning at the end to release my final results on github.

There is already a feature request for twig support:

https://github.com/mautic/mautic/issues/849

Thank you escopecz
nice to see it as popular request

Cheers
-Alessio

Hope it can be helpful
this is what I roughly meant to achieve
https://github.com/afelicioni/mautic-linux

That is a nice plugin! The only thing I’d done differently is the plugin description. I think it’s better to use English for it. Since Mautic uses English by default. But that’s just a tiny issue. And also, it is your plugin so you can do whatever you want in it.

Is that a “proof of concept” plugin or did you really need to insert the latest Linux Kernel version to an email and didn’t want to just type it?

Hi, as you figured it out I arranged this repository, modifying the actual plugin I written: so this is indeed a proof of concept.

The original plugin inherits same files tree for bundle, but fetching data from different URL: since the original page designed to be read by final users supplies a complex tabular HTML response, I am picking via xpath string blocks I need via helper method.
The original helper method returns above values, so multiple tokens replacement work is done.

The original tabular data is changing asynchronously multiple times a day.

That’s cool. Thanks’s for sharing your plugin structure with the community! I’m sure your plugin will save a lot of time for other developers.