Created
November 22, 2011 13:39
-
-
Save montylounge/1385681 to your computer and use it in GitHub Desktop.
include_raw from http://djangosnippets.org/snippets/1684/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django import template | |
| from django.template.loaders.app_directories import load_template_source | |
| register = template.Library() | |
| def do_include_raw(parser, token): | |
| """ | |
| Performs a template include without parsing the context, just dumps the template in. | |
| """ | |
| bits = token.split_contents() | |
| if len(bits) != 2: | |
| raise TemplateSyntaxError, "%r tag takes one argument: the name of the template to be included" % bits[0] | |
| template_name = bits[1] | |
| if template_name[0] in ('"', "'") and template_name[-1] == template_name[0]: | |
| template_name = template_name[1:-1] | |
| source, path = load_template_source(template_name) | |
| return template.TextNode(source) | |
| register.tag("include_raw", do_include_raw) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment