#1
by
frafed
Hi all, I want to show other players' information on the html page according to a specific order. Do you know if it is possible to get player in a specific order when using the command "for p in group.get_player" (for example, player 4, then player 2, then player 3)? This is how i set the code, but i am not getting the desired order. {% for p in group.get_players %} {% if p.id_in_group == 4 %} {{p.contribution}}, {{p.x}} {% formfield player.x4 %} {% formfield player.y4 %} {%endif%} {% if p.id_in_group == 2 %} {{p.contribution}}, {{p.x}} {% formfield player.x2 %} {% formfield player.y2 %} {%endif%} {% if p.id_in_group == 3 %} {{p.contribution}}, {{p.x}} {% formfield player.x3 %} {% formfield player.y3 %} {%endif%} {% endfor %} Thank you so much! Francesca
#2
by
Chris_oTree
Generate the list of players in vars_for_template and reorder it there. Then pass this already ordered list to your template, so then you just need to do: {{ for p in ordered_players }} …
#3
by
frafed
thank you! And would something like {for p in group.get_players_randomly} work?
#4
by
Chris_oTree
Potentially but I recommend doing it with vars_for_template.
#5
by
frafed
Hi Chris, I have tried to use vars_for_template, but I don't think I am doing it correctly. This is how I set it, but it's not working def vars_for_template(player): participant.vars['ordered_players']= player.get.player_by_id(3), player.get.player_by_id(4), player.get_player_by_id(2) return (participant.vars) and then in the page i just call: {% for p in ordered_players %} {% if p.id_in_group == 3 %}