sighmon / mjml-rails

MJML + ERb/Haml/Slim view template
https://mjml.io
Other
301 stars 65 forks source link

unable to load included template when using MRML #123

Open lucasmello opened 4 months ago

lucasmello commented 4 months ago

I'm trying to use mjml-rails along with mrml and I'm not being able to make it work. I added the mrml gem as well as set use_mrml = true in the initializer. The issue is my template has Ruby code. If I remove the Ruby code, it works fine.

Steps to reproduce

Just try to render a template like:

# my_template.mjml

<mj-section>
  <mj-column>
       <mj-text>Hello user <%= @user.name %></mj-text>
  </mj-column>
</mj-section>

The error is: MRML::Error: unable to load included template

This WORKS with mjml, but not with mrml.

sighmon commented 4 months ago

@lucasmello How is your controller setup? My controller/view works for both mjml and mrml:

  def email
    @issue = Issue.find(params[:issue_id])

    respond_to do |format|
      format.html { render :layout => 'email' }
      format.text { render :layout => false }
      format.mjml { render :layout => false }
    end
  end
lucasmello commented 3 months ago

@sighmon thanks for the reply, and sorry for the delay in replying back!

I'm using it on the notifier.rb:

def existing_user_invitation(user)
    mail(
      to: user.email,
      from: "my@email.com",
      subject: "Invitation to Join Account"
    ) do |format|
      format.mjml
    end
  end
sighmon commented 3 months ago

@lucasmello Would you mind creating a sample project showing your bug?

markvaneijk-websend commented 1 week ago

@lucasmello I happened to come across the same error in our codebase. I think ERB is getting skipped. If you rename my_template.mjml to my_template.mjml.erb it probably works.