Do you need access to those properties in your template? Or do you just want to store some values based on the email?
If it's the later, you could use NotificationCenter.EmailTemplate.MailSending event which has it's sender param set to the EmailTemplate instance that is being sent. Unfortunately this is fired after the razor template has been run, but as a dirty work around, you could render some placeholders in your template and then in the event handler, replace them in the mail message body?
I don't think we really have an easy way to know which email template it is from within the razor file itself.
We need some properties rendered in the razor template.
A future request from us would be that the emailTemplate, Id or Alias is being sent with it as a Querystring? As far as i can see, the querystring already contains storeId & id of the order.
What we ended up doing was to add 2 email templates. A basic template for all email templates in TeaCommerce like receivedOrder, confirmedOrder, completedOrder and trackAndTraceOrder. We also added a kind of layout template that render the basic template as it's body.
Then we intercept the generated email in the NotificationCenter.EmailTemplate.MailSending event and then get the template path by TemplatingService.Instance.GetTemplateFiles().SingleOrDefault(x => x.Contains("layout.cshtml")) and then rendering the template by TemplatingService.Instance.RenderTemplateFile(string templateFile,T Model, long? languageId) with our custom Model and replace the MailMessage.Body with it the result.
How to get Email Template Alias from TemplateContext with Order as Model
Hi all..
Using Umbraco 7.15.3 and TeaCommerce 3.3.2
How can we access the EmailTemplate Alias from the email template razor file that are using
@inherits TemplateContext<Order>
?We need to get the alias so we can get alot of custom properties assigned to that email template alias.
Hey Bo,
Do you need access to those properties in your template? Or do you just want to store some values based on the email?
If it's the later, you could use
NotificationCenter.EmailTemplate.MailSending
event which has it'ssender
param set to theEmailTemplate
instance that is being sent. Unfortunately this is fired after the razor template has been run, but as a dirty work around, you could render some placeholders in your template and then in the event handler, replace them in the mail message body?I don't think we really have an easy way to know which email template it is from within the razor file itself.
Matt
Hi Matt.
We need some properties rendered in the razor template.
A future request from us would be that the emailTemplate, Id or Alias is being sent with it as a Querystring? As far as i can see, the querystring already contains storeId & id of the order.
I will take alook into the dirty workaround :)
Hi Matt.
What we ended up doing was to add 2 email templates. A basic template for all email templates in TeaCommerce like receivedOrder, confirmedOrder, completedOrder and trackAndTraceOrder. We also added a kind of layout template that render the basic template as it's body.
Then we intercept the generated email in the
NotificationCenter.EmailTemplate.MailSending
event and then get the template path byTemplatingService.Instance.GetTemplateFiles().SingleOrDefault(x => x.Contains("layout.cshtml"))
and then rendering the template byTemplatingService.Instance.RenderTemplateFile(string templateFile,T Model, long? languageId)
with our customModel
and replace theMailMessage.Body
with it the result.Nicely done sir
I'll see what I can do to extend this in a future build so this can be made simpler, but glad you managed to get something to work in the mean time.
Matt
It's Dirty, but i like it :)
is working on a reply...