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

How to use this library to generate a string of raw html? #97

Open
nratter opened this issue Aug 22, 2022 · 1 comment
Open

How to use this library to generate a string of raw html? #97

nratter opened this issue Aug 22, 2022 · 1 comment

Comments

@nratter
Copy link

nratter commented Aug 22, 2022

I'm looking to build a client-side 'preview' of an email using this library. Since mjml runs on the server, is there a way we can use this library to generate an html string that can then be used to pass to the client?

@sighmon
Copy link
Owner

sighmon commented Aug 22, 2022

@nratter For sure. Here's how I use it for that purpose:

# controller.rb

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

    respond_to do |format|
      format.text { render :layout => false }
      format.mjml { render :layout => false }
    end
  end
# email.mjml

<mjml>
	<mj-head>
		<mj-preview><%= "The #{@issue.release.strftime("%B %Y")} issue of New Internationalist has been published.</mj-preview>
	</mj-head>
...

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

2 participants