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

Using with Blade templates #32

Closed
davidbarker opened this issue Nov 6, 2017 · 17 comments
Closed

Using with Blade templates #32

davidbarker opened this issue Nov 6, 2017 · 17 comments

Comments

@davidbarker
Copy link

davidbarker commented Nov 6, 2017

Hello. HEML looks super useful! I'd like to use it to build our Blade templates (for use with Laravel), however, I'm wondering how to get around the following issue.

For example, in my Blade file, I use

<a href="http://{{ $domain }}/auth/verify/{{ $user['confirmation'] }}">@lang('email.confirm_button')</a>

I want the contents inside the {{ }} tags to effectively be ignored by HEML. It mostly works, but there's a problem with the quotation marks. Using the online editor, the above gives

<a href="http://{{ $domain }}/auth/verify/{{ $user[&#39;confirmation&#39;] }}" class="a"><span class="a__text">@lang('email.confirm_button')</span></a>

which is almost perfect, but the ' is replaced by &#39;.

If I include heml-ignore on the tag then the template parts work, but then I lose the HEML specific additions for a link.

<a href="http://{{ $domain }}/auth/verify/{{ $user['confirmation'] }}" heml-ignore="">@lang('email.confirm_button')</a>

Any ideas? Thanks!

@avigoldman
Copy link
Contributor

Hey David 👋

Thanks so much for all the detail on this! I'm going dig into this one, and I'll post an update as soon as I have more info!

@davidbarker
Copy link
Author

You're welcome — thanks for a great tool!

@outcassed
Copy link

outcassed commented Nov 8, 2017

I'm also using HEML with a template engine (ERB, which uses <% %> ). I had to choose some characters and then substitute them after heml building.

It would be great if there was some HEML tag for surrounding text that you'd like to be inserted into the HTML without any transformations. Like <t><%='Hello, World%></t>

edit hm. that idea wouldn't help davidbarker with using templates inside of HEML tag attributes. Maybe if you could configure the opening/closing tags that will surround things that should be left alone?

@brunah
Copy link

brunah commented Nov 8, 2017

issue

@brunah
Copy link

brunah commented Nov 8, 2017

Issue

@LinusU
Copy link

LinusU commented Nov 14, 2017

Hmm, isn't a better workflow to first process with the template engine, and then put it into HEML?

I think it could be very nice if the heml cli tool would allow to plug and play template engines into it, sort of like express does...

This approach will only work if you do invoke heml when rendering the final email though...

@davidbarker
Copy link
Author

davidbarker commented Nov 14, 2017

Well the values in the template will be replaced at runtime. So, before each email is sent it would have to run HEML on every email. Unless I'm misunderstanding you?

@LinusU
Copy link

LinusU commented Nov 14, 2017

Yeah, I didn't think of the use case of compiling the templates before, I'm currently rendering with heml directly when I make the email call and thus have no problem templating before. It's just a bit inconvenient when previewing the emails...

I didn't consider that you can also compile the heml first and then use it multiple times, my bad...

@davidbarker
Copy link
Author

No problem! It's possible both ways, I suppose. I just like to generate the template once and know exactly what I'm sending out (minus the variables).

@LinusU
Copy link

LinusU commented Nov 14, 2017

Yeah, that's actually quite smart. Do you check in the compiled templates into source control?

@davidbarker
Copy link
Author

I've not actually done it yet, but that's my plan. I'd have the HEML templates stored somewhere, run a Gulp command to generate the Blade files, and then probably check in both the HEML and the Blade. That way someone could recompile them if they change the HEML.

@LinusU
Copy link

LinusU commented Nov 15, 2017

I actually got quite lucky here, I'm using SES to send my emails and they actually support templating out of the box. My workflow ended up going (build time) HEML -> HTML -> SES Template.

I'm now convinced though that the the best way is to do HEML compilation first, and then templating. Since this avoids wasting a ton of cpu to do basically the same work over and over again.

So, could a solution to this problem be something like this:

We add some new configuration options, maybe { templateStartDelimiter: '{{', templateStopDelimiter: '}}' }

When these are set, heml will recognise the {{ and simply pass everything thru as is, without any extra quoting, until the }} is found. That way it will work when passing it to the template engine.

@avigoldman
Copy link
Contributor

I like that idea @LinusU. Thought it would be nice to have this handled correctly by default. I don't imagine any situation where someone would want <a href="http://{{ $domain }}/auth/verify/{{ $user['confirmation'] }}"> to be encoded to <a href="http://{{ $domain }}/auth/verify/{{ $user[&#39;confirmation&#39;] }}" class="a">

Am I missing a use case where the current functionality is desired?

@avigoldman
Copy link
Contributor

avigoldman commented Nov 21, 2017

Digging into it, the problem is stemming from the stringify-attributes library. Its a fairly simple function, so I think the best solution is to pull the functionality in, without the escaping. Thoughts?

Edit: See #37 for the implemented solution

@LinusU
Copy link

LinusU commented Nov 21, 2017

Sounds good 👍

The only problem I can think of is that there are many different template systems out there. Ejs is quite common in the Node.js community and uses <% and %>. Some moustache flavours uses only a single { and }.

edit: didn't read the last message, seems good 👍

@avigoldman
Copy link
Contributor

#37 was merged in and released in 1.1.2!

@davidbarker
Copy link
Author

Fantastic! I’m excited to try it out. Thank you so much, @avigoldman.

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

5 participants