Sunday, October 30, 2011

Re: variables in a dict in a template

One way to go about it is to create multiple, nested objects. For example:

Score
- Rounds
---- Holes

Then in your template, you'd do something along the lines of:

{% for round in game.rounds %}
{% for hole in round.holes %}
{{ hole.score }}
{% endfor %}
{% endfor%}

Hopefully that helps a little :)

On Sun, Oct 30, 2011 at 10:52 AM, kenneth gonsalves <lawgon@thenilgiris.com> wrote:
hi,

I have a dict which I use to store golf scores to display. Template
syntax is:

{{pl.1.1.scores.1.sc}} for the first hole of the first round
{{pl.1.2.scores.1.sc}} for the first hole of the second round
{{pl.1.1.scores.2.sc}} for the second hole of the first round
etc

I want to do:
{{pl.1.round_no.scores.hole_no.sc}}

where round_no and hole_no are variables passed to the template. Can it
be done?
--
regards
Kenneth Gonsalves

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment