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

Compiling partial without adding surrounding HTML tags #459

Closed
danielsunnerberg opened this issue Dec 5, 2016 · 9 comments
Closed

Compiling partial without adding surrounding HTML tags #459

danielsunnerberg opened this issue Dec 5, 2016 · 9 comments

Comments

@danielsunnerberg
Copy link

Hi, great work -- makes my life a lot easier!

I have a partial MJML-file which I'd like to render (without a parent) without the surrounding HTML tags. I tried rendering it without the parent mj-body/mjml-tags, but that doesn't seem to be valid syntax.

Reproduction Steps:
Compile the following partial MJML-file:

<mjml>
  <mj-body>
    <mj-text>
      <p>Foo</p>
    </mj-text> 
  </mj-body>
</mjml>

Expected behavior:
Generates only the relevant HTML-code for a partial:

<div style="cursor:auto;color:#000000;font-family:Ubuntu, Helvetica, Arial, sans-serif;font-size:13px;line-height:22px;">
  <p>Foo</p>
</div>

Observed behavior:
Generates the full HTML, with surrounding HTML tags:


<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
<head>
  <title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
  #outlook a { padding: 0; }
  .ReadMsgBody { width: 100%; }
  .ExternalClass { width: 100%; }
  .ExternalClass * { line-height:100%; }
  body { margin: 0; padding: 0; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; }
  table, td { border-collapse:collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; }
  img { border: 0; height: auto; line-height: 100%; outline: none; text-decoration: none; -ms-interpolation-mode: bicubic; }
  p { display: block; margin: 13px 0; }
</style>
<!--[if !mso]><!-->
<style type="text/css">
  @media only screen and (max-width:480px) {
    @-ms-viewport { width:320px; }
    @viewport { width:320px; }
  }
</style>
<!--<![endif]-->
<!--[if mso]>
<xml>
  <o:OfficeDocumentSettings>
    <o:AllowPNG/>
    <o:PixelsPerInch>96</o:PixelsPerInch>
  </o:OfficeDocumentSettings>
</xml>
<![endif]-->
<!--[if lte mso 11]>
<style type="text/css">
  .outlook-group-fix {
    width:100% !important;
  }
</style>
<![endif]-->

<!--[if !mso]><!-->
    <link href="https://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700" rel="stylesheet" type="text/css">
    <style type="text/css">

        @import url(https://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700);

    </style>
  <!--<![endif]--></head>
<body>
  <div style="cursor:auto;color:#000000;font-family:Ubuntu, Helvetica, Arial, sans-serif;font-size:13px;line-height:22px;">
      <p>Foo</p>
    </div>
</body>
</html>

Perhaps a --partial flag would be a good idea?

@iRyusa
Copy link
Member

iRyusa commented Dec 5, 2016

Hi there,

First, I would like to know the use case of such an option ?

To me, a component like mj-column cannot live outside an html document because there's some media queries attached to it in the head.

@danielsunnerberg
Copy link
Author

Hi!

Yeah, that makes sense. I'm rendering the compiled partial through Twig, which itself extends a parent template. I suppose a better solution would be to add support for inheritance in MJML.

@iRyusa
Copy link
Member

iRyusa commented Dec 5, 2016

I don't know how twig works, but you should apply all twig variables & conditionnal structures to it and then pass it to the MJML engine ? ( Twig -> MJML -> HTML )

@danielsunnerberg
Copy link
Author

Thank you for the feedback; I attacked the problem from the wrong direction.

@nthgol
Copy link

nthgol commented Apr 28, 2019

I think this is a valid request.
We send specially id'd <div>s to the client that can be Rich text edited, but the default html in such a div is generated by mjml.

@iRyusa
Copy link
Member

iRyusa commented Apr 28, 2019 via email

@nthgol
Copy link

nthgol commented Apr 28, 2019

Couple examples:

<mj-text> //cannot put custom attributes on mj components
<div editable=true database-field='customTitle'>
   {{#if customTitle}}
      {{{customTitle}}}
   {{else}}
    {{{insert some default html here}}} //ideally an mjml partial
   {{/if}}
</div>
</mj-text>

Is there a way to make this work? I tried using mjml2html for the default and ran into this issue thread

@iRyusa
Copy link
Member

iRyusa commented Apr 28, 2019 via email

@kmcb777
Copy link
Collaborator

kmcb777 commented Apr 28, 2019

concerning the ideally an mjml partial, note that you can't use mjml components in a mj-text. It only takes html, and keeps it unchanged.

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

4 participants