Beispiel #1
0
def do_include_ich(parser, token):
    bits = token.split_contents()
    template_name = bits[1]
    if template_name[0] in ('"', "'") and template_name[-1] == template_name[0]:
        template_name = template_name[1:-1]

    block_name, block_type = basename(template_name).rsplit('.', 1)
    source, path = _loader.load_template_source(template_name)

    render = '<script id="tpl_%s" type="text/%s">\n%s\n</script>' % (block_name, block_type, source)

    if 'partial' in bits:
        render += '<script id="tpl_partial_%s" type="text/%s" class="partial">\n%s\n</script>' % (block_name, block_type, source)

    return template.TextNode(render)
Beispiel #2
0
def do_include_raw(parser, token):
    """
    Performs a template include without parsing the context, just dumps
    the template in.
    Source: http://djangosnippets.org/snippets/1684/
    """
    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 = _loader.load_template_source(template_name)

    return template.TextNode(source)
Beispiel #3
0
def do_include_raw(parser, token):
    """
    Performs a template include without parsing the context, just dumps
    the template in.
    Source: http://djangosnippets.org/snippets/1684/
    """
    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 = _loader.load_template_source(template_name)

    return template.TextNode(source)