[Mail template] Adapt mail subject to a blog post content

Hi all,

I’m trying to adapt mail subject to a blog post content by changing mail template (xwiki/bin/edit/XWiki/Notifications/MailTemplate?editor=object&classname=XWiki.Mail&object=0&force=1).

Is it possible to add velocity content into “subject” ? I’d like to change mail subject according to the content of a blog post. Something like that :

#if ($blog_post_content.contains("incident"))
  # set ($subject = "New incident")
#else
  # set ($subject = "$services.localization.render('notifications.email.subject', [$events.size()])")
#end

Is it possible to do such a thing ? Do I have to modify macro.vm file ? Otherwise, what about adding to different XWiki.mail objects ?

Regards

MailTemplate’s default content uses velocity so yes, velocity is used to render its content.

You just need to edit XWiki.Notifications.MailTemplate as indicated on https://extensions.xwiki.org/xwiki/bin/view/Extension/Notifications%20Application/#HCustomizingthenotificationemailtemplate

You can add different xobject for different languages, yes.

Hi Vincent,

Thanks for the quick reply.
I’ve already modifyed this template, but I’ve only been able to modify the mail body but not the mail subject.
It seems that it’s not possible to add velocity code into subject part because editor permits only one line into it.

I don’t think that adding an other object to manage languages is the answer for my question.
What could I do to make mail subject variable according to mail content ?

Regards

Marc

The subject xproperty is also rendered using velocity. By default, it is: $services.localization.render('notifications.email.subject', [$events.size()])

So you just need to modify it.

Sorry, I don’t think we’re understanding each other. I know the default value :
$services.localization.render(‘notifications.email.subject’, [$events.size()])
in mail template.

But, I’d like it to be variable according to the message content, something like that :

#if ($blog_post_content.contains("incident"))
  # set ($subject = "New incident")
#else
  # set ($subject = "$services.localization.render('notifications.email.subject', [$events.size()])")
#end

But the editor doesn’t allow to enter several lines. Where should I had this code ?

I think we do understand each other…

In the title field… On a single line (since it only supports one line of text).

OK, understood this time :slight_smile:
I’ll try it and write down results here

Thanks a lot

Hi,

I tried to execute any velocity simple code into the “subject” field, but it did’nt work : no mail was sent.
I won’t investigate more as we decided to change the way to notify users (through teams chanels).
Thanks a lot for the answers anyway

Marc