On Oct 6, 12:46 pm, Stephen Cheng <[EMAIL PROTECTED]> wrote:
> Hi django friends
>
> I got a problem with varible reference in template. the case is like
> this:
>
> I pass a map to a template, I am trying to get map[key], in the case
> the key= modelA.id, then I have to use map.modelA.id, then it won't
> work.
>
> How can I conquer this? Can I assign modelA.id to another varible? I
> don't know how to handle this. Please help.
>
> Thank you.


Try a custom filter:

@register.filter
def lookup(mapping, key):
  return mapping[key]

and in the template:
{{ mapping|lookup:modelA.id }}

--
DR
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to