views:

40

answers:

1

Hi, I am suffering whereever i try to do something in django that is not common(in django, not in python in general)

For example, i don't know how to return an inclusion tag. This. obviously, won't work:

@register.inclusion_tag('template.tpl')
def myinclusiontag(parameter):
    return {'var': parameter.attr1}


@register.inclusion_tag('template2.tpl')
def myinclusiontag2(parameter):
    return {'var': parameter.attr2}

@register.simple_tag
def mysimpletag(paramter):
    if parameter.attr: return myinclusiontag(parameter)
    else: return myinclusiontag2(paramter)

mysimpletag return a dict(first returned by the inclusion tag), wich is a normal behaviour, but this is not my i want.

help pls

A: 

Could you just use the simple tag on it's own:

@register.simple_tag
def mysimpletag(parameter):
    if parameter.attr:
        t = loader.get_template('template.tpl')
        parm = parameter.attr1
    else:
        t = loader.get_template('template2.tpl')
        parm = parameter.attr2

    return t.render(Context({'var':parm}))
Stuart Marsh