On Feb 10, 2:07 pm, Bobby Roberts <tchend...@gmail.com> wrote: > Hi. I have the following template tag: > > @register.filter(name='elementtotext') > @stringfilter > def elementtotext(string): > itext='Unknown' > if string=='DR': > itext='Door' > if string=='FL': > itext='Flooring' > if string=='FO': > itext='Foundation' > if string=='FR': > itext='Framing' > if string=='GR': > itext='Grounds' > if string=='HV': > itext='HVAC / Utilities' > if string=='MI': > itext='Miscellaneous' > if string=='RF': > itext='Roof' > if string=='WM': > itext='Wall Material' > if string=='WI': > itext='Window' > return itext > > The purpose of the tag is to take a record set field value and return > the text equivalent of that value. My field name in this example is > tm.element. > > I can print the raw code to the screen fine but I'm having trouble > running it through my template tag. Can someone tell me the proper > syntax? > > I'm trying {% elementtotext tm.element %} and it errors out. > > I'm using python2.5 and django .97 or thereabout.
This is a filter, not a tag. So you just use the filter syntax on a variable: {{ tm.element|elementtotext }} By the way, you might find it easier to use a dictionary to map your template strings, rather than a whole load of if/else blocks: mapping = { 'DR': 'door', (etc) } itext = mapping.get(string, 'unknown') -- DR. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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 -~----------~----~----~----~------~----~------~--~---