librelist archives

« back to archive

jinja and handlebars?

jinja and handlebars?

From:
Matthew Hoopes
Date:
2012-10-21 @ 03:44
Hi,

Is there an easy way to include client side templates (specifically
handlebars) in jinja templates? I've been googling/stackoverflowing, and
haven't found any real guidance or best practices for this.

I have a bunch of handlebars templates, and they have things like {{#if...
and {{#else...  which screw up the jinja parser. My first inclination,
which is working, is to wrap every js template in {% raw %}, but that seems
heavy-handed (at least to me).

Maybe I could name the template files with a .template extension, and have
jinja auto-render them as raw?

Anyway, I'd appreciate any advice or previous experience. Thanks in advance!

Re: [flask] jinja and handlebars?

From:
Steven Kryskalla
Date:
2012-10-21 @ 04:37
On Sat, Oct 20, 2012 at 8:44 PM, Matthew Hoopes
<matthew.hoopes@gmail.com> wrote:
> I have a bunch of handlebars templates, and they have things like {{#if...
> and {{#else...  which screw up the jinja parser. My first inclination, which
> is working, is to wrap every js template in {% raw %}, but that seems
> heavy-handed (at least to me).

You could change the delimiter that jinja2 uses by overriding
Flask.jinja_options, like this:

https://gist.github.com/3925738

Or you could define the mustache templates outside of the jinja
templates, then render them into the template by passing them in
through a variable:

https://gist.github.com/3925780

But that won't work if you want to use jinja variables in the mustache
template. You could use normal string interpolation ('%s', '%d', etc.)
for that.

-steve

Re: jinja and handlebars?

From:
Chris Hancock
Date:
2013-07-15 @ 23:12
Try the {{ raw }} tag to maintain the template code.