Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instance variables not working in templates #22

Closed
RemiKalbe opened this issue Jul 10, 2019 · 3 comments
Closed

Instance variables not working in templates #22

RemiKalbe opened this issue Jul 10, 2019 · 3 comments

Comments

@RemiKalbe
Copy link

RemiKalbe commented Jul 10, 2019

I created a text and HTML template, I have a couple of instance variables but when the email is sent the variables aren't replaced by their value they stay like that #{@name_of_the_variable}.

My class is like that:

class ConfirmationEmail < BaseEmail
    @title : String
    @sub_title : String
    @body : String

    def initialize(@email_address : String, @language : String, @confirmation_code : String)
      @title = translate("email_confirmation_title", @language, Nil)
      @sub_title = translate("email_confirmation_sub_title", @language, Nil)
      @body = translate("email_confirmation_body", @language, Nil)
    end

    to @email_address
    subject translate("email_confirmation_subject", @language, Nil)
    reply_to "[email protected]"
    templates text, html
  end

Here is my text template, couldn't be simpler:

#{@title}
#{@sub_title}

#{@body}


#{@confirmation_code}

I won't show my HTML template it's way too big. And I don't think it matters as the issue also involve the text template.

So when the email is sent, I receive the email like that:

#{@title}
#{@sub_title}

#{@body}


#{@confirmation_code}

Not, with the actual values.

Am I doing something wrong here?

@RemiKalbe
Copy link
Author

I figured it out!

I replaced

#{@name_of_the_variable}

by

<%= @name_of_the_variable -%>

( from https://crystal-lang.org/api/0.21.1/ECR.html )

And now it works!

@y2k2mt
Copy link
Contributor

y2k2mt commented Oct 6, 2020

I got same.
I created a new PR.
#35

@paulcsmith
Copy link
Member

Glad you got this figured out, and sorry for the confusion in the README!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants