hello, thanks for posting.
te way i do it is by creating a variable: {% let email = company.contact.email %} after that you can use email variable just like any other. konstantin class LetNode(Node) : def __init__(self, var, expr) : self.var, self.expr = var, expr def render(self, context) : try : context[self.var] = resolve_variable(self.expr, context) except VariableDoesNotExist : context[self.var] = None return '' LET_TAG_RE = re.compile(r'^\s*let\s+(\w+)\s*=\s*(\S+)\s*$') @register.tag def let(parser, token) : m = LET_TAG_RE.search(token.contents) if not m : raise TemplateSyntaxError, 'invalid syntax' return LetNode(*m.groups()) On Mar 22, 8:35 am, "Andrew Durdin" <[EMAIL PROTECTED]> wrote: > Recently I've found myself repeating variables many times in > templates, much like this: > > {% if company.contact.email %} > <h3>Email address</h3> > <a href='mailto: > {{ company.contact.email }}'>{{ company.contact.email }}</a> > {% endifvalue %} > > This repetition is annoying, as well as inefficient if company.contact > involves a ForeignKey lookup. > > I've created a pair of tags, "ifvalue" and "ifnotvalue", to > encapsulate this behaviour: > > {% ifvalue company.contact.email as email %} > <h3>Email address</h3> > <a href='mailto:{{ email }}'>{{ email }}</a> > {% endifvalue %} > > The full code for the tag is athttp://www.djangosnippets.org/snippets/124/ > > Andrew --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---