leemunroe / grunt-email-workflow

A Grunt workflow for designing and testing responsive HTML email templates with SCSS.
MIT License
3.05k stars 339 forks source link

Assemble Parse Error #64

Closed ghost closed 8 years ago

ghost commented 8 years ago

How can I use PHP echo statements in my templates?

I'm creating a whole set of html email template to drop into a PHP application. The end result in the templates once they've been compiled, needs to retain the <?= $variable; ?> so that they can be parsed in the application.

I tried escaping them with {{{ <?= $variable; ?> }}} but assemble throws an error.

Warning: Parse error on line 25:
...         <h1>Hi {{{ <?= $variable; ?> }
-----------------------^
Expecting 'ID', 'STRING', 'NUMBER', 'BOOLEAN', 'UNDEFINED', 'NULL', 'DATA', 
got 'INVALID' Use --force to continue.

Template looks like so:


---
layout: template.hbs
subject: Forgotten Password
preheader: Whoops, looks like you've forgotten your password.

---
<table class="main">
  <tr>
    <td class="wrapper">
      <table>
        <tr>
          <td>
            <h1>Hi {{{ <?= $firstname; ?> }}}</h1>
            <p>
              Either you or someone claiming to be you has requested to change
              your password on the <a href="{{ default.site_url }}">{{ default.site_name }}</a> website.
            </p>
            {{> divider }}
            <p>Here is your new password:</p>
            {{> notice type='info' class='align-center' text='<strong>{{{ <?= $password; ?> }}}</strong>'}}
            {{> divider }}
            <p>
              Please use this password to login to your account, then change
              your password to something you'll remember and is more secure.
            </p>
            <p>Thanks.</p>
            <p>{{ default.team_text }}</p>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>

Ideas?

taeo commented 8 years ago

Don't wrap your php in handlebars notation. PHP tags will be passed through assemble / handlebars unmodified if you write them as normal. {{{ <?= $firstname; ?> }}} should be simply <?php echo $firstname; ?>

NOTE: The previewer will not parse or display your php code and the templates will still have .html extensions. You can go the extra mile to support .php extensions.

in file grunt/assemble.js add:

options:
    ext: '.php'

Then for preview you'd have to add express-php via npm and in file server.js adapt the view engine from ejs to php

ghost commented 8 years ago

Well chalk one up to thinking way too far into it.

Thanks so much.