mjml-rails icon indicating copy to clipboard operation
mjml-rails copied to clipboard

unable to load included template when using MRML

Open lucasmello opened this issue 1 year ago • 4 comments

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.

lucasmello avatar Jul 23 '24 19:07 lucasmello

@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

sighmon avatar Jul 26 '24 12:07 sighmon

@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: "[email protected]",
      subject: "Invitation to Join Account"
    ) do |format|
      format.mjml
    end
  end

lucasmello avatar Jul 31 '24 12:07 lucasmello

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

sighmon avatar Aug 01 '24 04:08 sighmon

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

markvaneijk-websend avatar Nov 15 '24 15:11 markvaneijk-websend

I'm still having the same issue on 4.15.1.

If I name my file email.mjml and it contains ERB tags (<%= ... %>) then the template rendering will fail with:

MRML::Error: unable to load included template

Renaming the file email.mjml.erb gets rid of the error but then the MJML tags are ignored and I end up with this rendered instead of HTML:

<mjml>
  <mj-head>
    <mj-title>Mail title</mj-title>
    <mj-attributes>
      ...
    </mj-attributes>
  </mj-head>
  <mj-body>
     ...
  </mj-body>
</mjml>

I was hoping using MRML could fix my troubles using MJML in production. I just can't get my capistrano deployment setup to find the MJML binary. It works locally, it works when I ssh into production and run it from console, but the rails server always fails with:

Couldn't find the MJML 4. binary.. have you run $ npm install mjml?

Ideas ?


Edit: Actually it works with Sidekiq, but when I try to deliver an email directly from the Rails app I keep getting the error :

Couldn't find the MJML 4. binary.. have you run $ npm install mjml?

Edit 2: Ok I got it fixed, I just needed to fully restart the Unicorn process instead of just killing it with USR2 for "zero-downtime" restart. The MRML issue still remains though, even if I don't really need it now that MJML is working.

jerefrer avatar May 19 '25 09:05 jerefrer

@jerefrer Could you create a tiny sample app that reproduces the MRML bug?

sighmon avatar May 20 '25 07:05 sighmon