/django-jsmetatemplates

Template tag library for building building javascript templates using django templates

Primary LanguagePython

django-jsmetatemplates

Template tag library for building building javascript templates using django templates

Allows for javascript templates (like mustache.js ones) to be built using the inheritence and include functionality of django-templates before being rendered to the client.

Gets around the problem of overlapping delimiters by using a different delimiter for javascript templates that is then turned into the correct one during django template rendering.

An example:

js_template_base.html:

<div>
	<h1>{! title !}</h1>
	{% block content %}
	{% endblock %}
</div>

js_template_derivative.html:

{% extends 'js_template_base.html' %}

{% block content %}
<ul>
	<li>{! thing_one !}</li>
	<li>{! thing_two !}</li>
</ul>
{% endblock %}

page_template.html:

{% load jsmetatemplate %}

{% include_ichtemplate "js_template_derivative.html" %}

page_template.html will then render to:

<script type="text/html" id="js_template_derivative.html">
<div>
	<h1>{{ title }}</h1>
	<ul>
		<li>{{ thing_one }}</li>
		<li>{{ thing_two }}</li>
	</ul>
</div>
</script>