# How to properly extend emails?

**URL:** <https://forum.mautic.org/t/how-to-properly-extend-emails/2765>\
**Category:** General Discussion\
**Created:** [November 13, 2015, 11:23am UTC](https://forum.mautic.org/t/how-to-properly-extend-emails/2765 "2015-11-13T11:23:35Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![alessio](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/alessio/32/41_2.png) [@alessio](https://forum.mautic.org/u/alessio)\
**Post date:** [November 13, 2015, 11:23am UTC](https://forum.mautic.org/t/how-to-properly-extend-emails/2765/1 "2015-11-13T11:23:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![alessio](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/alessio/32/41_2.png) [@alessio](https://forum.mautic.org/u/alessio)\
**Post date:** [November 13, 2015, 11:23am UTC](https://forum.mautic.org/t/how-to-properly-extend-emails/2765/2 "2015-11-13T11:23:35Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)\
**Post date:** [November 13, 2015, 12:36pm UTC](https://forum.mautic.org/t/how-to-properly-extend-emails/2765/3 "2015-11-13T12:36:02Z")

</div>

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](https://github.com/mautic/mautic/blob/staging/app/bundles/PageBundle/EventListener/BuilderSubscriber.php)

---

<div class="post-metadata">

**Author:** ![alessio](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/alessio/32/41_2.png) [@alessio](https://forum.mautic.org/u/alessio)\
**Post date:** [November 16, 2015, 5:48pm UTC](https://forum.mautic.org/t/how-to-properly-extend-emails/2765/4 "2015-11-16T17:48:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)\
**Post date:** [November 16, 2015, 7:41pm UTC](https://forum.mautic.org/t/how-to-properly-extend-emails/2765/5 "2015-11-16T19:41:33Z")

</div>

There is already a feature request for twig support:

[https://github.com/mautic/mautic/issues/849](https://github.com/mautic/mautic/issues/849)

---

<div class="post-metadata">

**Author:** ![alessio](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/alessio/32/41_2.png) [@alessio](https://forum.mautic.org/u/alessio)\
**Post date:** [November 16, 2015, 10:12pm UTC](https://forum.mautic.org/t/how-to-properly-extend-emails/2765/6 "2015-11-16T22:12:26Z")

</div>

Thank you escopecz  
nice to see it as popular request

Cheers  
-Alessio

---

<div class="post-metadata">

**Author:** ![alessio](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/alessio/32/41_2.png) [@alessio](https://forum.mautic.org/u/alessio)\
**Post date:** [November 22, 2015, 5:12pm UTC](https://forum.mautic.org/t/how-to-properly-extend-emails/2765/7 "2015-11-22T17:12:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)\
**Post date:** [November 22, 2015, 5:27pm UTC](https://forum.mautic.org/t/how-to-properly-extend-emails/2765/8 "2015-11-22T17:27:03Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![alessio](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/alessio/32/41_2.png) [@alessio](https://forum.mautic.org/u/alessio)\
**Post date:** [November 22, 2015, 7:00pm UTC](https://forum.mautic.org/t/how-to-properly-extend-emails/2765/9 "2015-11-22T19:00:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)\
**Post date:** [November 22, 2015, 7:04pm UTC](https://forum.mautic.org/t/how-to-properly-extend-emails/2765/10 "2015-11-22T19:04:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![silavapi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/silavapi/32/7424_2.png) [@silavapi](https://forum.mautic.org/u/silavapi)\
**Post date:** [February 2, 2020, 10:57pm UTC](https://forum.mautic.org/t/how-to-properly-extend-emails/2765/11 "2020-02-02T22:57:03Z")

</div>


