oTree Forum >

Access player variables from previous round in html

#1 by nathalieroemer

hi everyone,
i tried to use {{ player.in_round(1).get_location_display }} in the html code, but I get the following error: Unparsable expression 'player.in_round(1).get_location_display' 

Can anyone help?
Thank you!
Nathalie

#2 by ccrabbe

Hi Nathalie -

The way I would do this is to pick out that element in vars_for_template, and then display it.

so:

class PreviousRoundItem(Page):
    @staticmethod
    def vars_for_template(player: Player):
        rval = {}
        rval['previous_item'] = player.in_round(1).get_location_display()
        return rval
        
And then in the template I would use {{ previous_item }} to display it.  You can use vars_for_template to prepare any more-complicated template items on the python-side of things and still display them in the template.

Thanks,
--Chris

Write a reply

Set forum username