Jinja variables in hrefs are HTML encoded. Outside of hrefs they're not encoded.
See original GitHub issuePremailer version 2.5.0.
I have an HTML template with Jinja variables in it. I’d like for these Jinja variables to remain after using premailer, so I can cache the premailed version and do variable substitution in a loop.
For variables in hrefs, like
<a href="{{ SURVEY_LINK }}" class="btn-primary">Start Survey</a>
Premailer HTML encodes the braces to their HTML-encoded entities:
<a href="%7B%7B%20SURVEY_LINK%20%7D%7D" class="btn-primary"...
Likewise, brackets, [
and ]
in href quotes are escaped, which is problematic for my use case as well.
I’d like to use premailer on my Jinja email templates but because of this HTML encoding issue I’m not able to.
Issue Analytics
- State:
- Created 9 years ago
- Reactions:4
- Comments:14 (5 by maintainers)
Top Results From Across the Web
Advanced: How to use href in Jinja2 - Stack Overflow
One way to add the id (from the Python variable a.id to your URL is to use the % string formatting operator, like...
Read more >Template Syntax
Template Syntax. This vignette describes the template syntax supported by jinjar, following the structure of the Jinja Template Designer Documentation.
Read more >API — Jinja Documentation (2.9.x)
This document describes the API to Jinja2 and not the template language. ... For Jinja2 the default encoding of templates is assumed to...
Read more >Jinja Filters - Bloomreach Documentation
Using String filters on non-String variables casts the variables to ... {# generate base64url-encoded strings out of JSONs #} {# replace ...
Read more >Primer on Jinja Templating - Real Python
Render a Jinja template in Flask; Use for loops and conditional statements with Jinja; Nest Jinja templates; Modify variables in Jinja with ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@skyler Looks like it is
lxml
notpremailer
related issue. See here: http://stackoverflow.com/questions/4684614/is-there-a-way-to-disable-urlencoding-of-anchor-attributes-in-lxmlUntil better solution is available, i used simple replace to fix the problem with
href="{{ }}"
. After string has been transformed fix it back:I ran into this issue as well with SendGrid marketing campaign emails, specifically for
[Weblink]
and[unsubscribe]
.I ended up chaining two
.replace().replace()
to.transform()
to look for the HTML encoded weblink and unsubscribe strings.