Hi all, I've been trying to figure this out for hours and hours, but I simply can't understand how to make it work.
Now, we have a very simple custom template tag. Let's say that we want the template tag to take as a parameter a filtered variable. A very simple implementation of my template tag is : register = template.Library() class Test(template.Node): def __init__(self,val): self.val = val def render(self,context): print("VALUE=%s" % self.val) if self.val.__class__.__name__ == "FilterExpression": self.val = self.val.resolve(context) return self.val @register.tag('test') def test(parser,token): print("Test is executed") val = token.split_contents()1 val = parser.compile_filter(val) return Test(val) This just gets the value and resolves the filter. A simple template to test this is : {% for p in test_list %} {% test p|first %} - {%test p|last%} --- {{p}}<br/> {% endfor %} The test_list is : (("First1","Last1"),("First2","Last2"),("First3","Last3")) So from the code I've written so far I would expect this silly template tag to iterate through and print out the first and last element of the tuples. Though, this is the output of the template : First1 - Last1 --- ('First1', 'Last1') First1 - Last1 --- ('First2', 'Last2') First1 - Last1 --- ('First3', 'Last3') And this is what I get in my console: Test is executed Test is executed VALUE=p|first VALUE=p|last VALUE=First1 VALUE=Last1 VALUE=First1 VALUE=Last1 OK, so what I understand so far is that the template player calls the test template tag the first two times. Then, somehow it creates new Test objects and feeds them with the result of the first execution. I am certainly not a django expert, so could someone be kind enough to explain me what on earth is this thing doing and how to get around it please ? :) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.