Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Bo Jacobsen 298 posts 1306 karma points
    Oct 18, 2019 @ 10:42
    Bo Jacobsen
    0

    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.

  • Matt Brailsford 2284 posts 11100 karma points MVP 6x c-trib
    Oct 18, 2019 @ 11:09
    Matt Brailsford
    0

    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'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.

    Matt

  • Bo Jacobsen 298 posts 1306 karma points
    Oct 18, 2019 @ 11:22
    Bo Jacobsen
    0

    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 :)

  • Bo Jacobsen 298 posts 1306 karma points
    Oct 18, 2019 @ 13:38
    Bo Jacobsen
    0

    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 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.

  • Matt Brailsford 2284 posts 11100 karma points MVP 6x c-trib
    Oct 18, 2019 @ 13:40
    Matt Brailsford
    0

    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

  • Bo Jacobsen 298 posts 1306 karma points
    Oct 18, 2019 @ 13:41
    Bo Jacobsen
    0

    It's Dirty, but i like it :)

Please Sign in or register to post replies

Write your reply to:

Draft