Skip to content

Instantly share code, notes, and snippets.

@pmclanahan
Created May 16, 2011 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmclanahan/975505 to your computer and use it in GitHub Desktop.
Save pmclanahan/975505 to your computer and use it in GitHub Desktop.
Django tag for ICanHaz.js templates
{# ICanHaz templates #}
{% icanhaz %}
{# inside here all occurrences of "[[" will become "{{" and "]]" will be "}}" #}
<script type="text/html" id="contributor_row">
<select name=role_for_[[ id ]]">
{% for role in roles %}
<option value="{{ role.id }}">{{ role.name }}</option>
{% endfor %}
</select>
<script>
{% endicanhaz %}
from django import template
register = template.Library()
@register.tag
def icanhaz(parser, token):
nodelist = parser.parse(('endicanhaz',))
parser.delete_first_token()
return ICanHazNode(nodelist)
class ICanHazNode(template.Node):
def __init__(self, nodelist):
self.nodelist = nodelist
def render(self, context, ):
output = self.nodelist.render(context)
return output.replace('[[', '{{').replace(']]', '}}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment