views:

146

answers:

3

I have writing a template tag and take it to the templates:

{% check_somethings value1 value2 as is_checked %}
{% if is_checked %}
    # do it
{% endif %}

But there are some errors. I am doing so right?

check_somethings takes 2 arguments

There are:

@register.simple_tag
def check_somethings(value1, value2):
    if Mymodel.objects.filter(f1=value1, f2=value2):
        return True
    else:
        return False
+1  A: 

Template tag parsing is very low level. You have passed your template tag four arguments: value1, value2, as, and is_checked. I'm not sure how to do what you want. I'd check the code of tags that already do it, and compare. I'm pretty sure @simpletag isn't going to cover it.

jcdyer
+1  A: 

Take a look at the smart if tag. Apparently it will be built in to 1.2.

czarchaic
In developing version of Django, it has added things like this.
Tran Tuan Anh
+1  A: 

The "as something" pattern is not built in to Django tags, your tag has to explicitly provide that functionality, which you can't do with simpletag. You'll have to write a full Node and parser function, which is harder than it ought to be; but you can look at examples of built-in tags.

Carl Meyer