Jonah
Jonah

Reputation: 10091

Jinja2 Import Static HTML in Pyramid

My application contains Angular code. I want Jinja2 templating within the layout, but need to be able to use Angular expressions within the page. I'd like to do that by importing a static HTML file into the main Jinja2 template that is not parsed.

How can I import an HTML template file without parsing it? A Jinja2 extension? If so, how?

Upvotes: 0

Views: 350

Answers (1)

Cameron
Cameron

Reputation: 98746

When you say "import", do you mean copying it in by hand, or do you mean you have some HTML in another file that you'd like injected (unparsed) somewhere within the template?

If it's the latter you're after -- including an HTML file without parsing -- you could write an extension, sure, but it's far simpler to just put the file's contents into a context variable (named, say, rawHtml) and output it like so:

{{ rawHtml }}

On the other hand, if you're writing the HTML inside the template itself and you want it rendered without interpretation, you can accomplish that too by using the raw construct:

{% raw %}
    <a href="#">He had a great moustache, like this :-{ </a>
{% endraw %}

Upvotes: 1

Related Questions