oTree Forum >

Opening Instructions page at a different page in the treatment

#1 by Paw

Hello, I want to create a link to the Instructions page from a different page in the treatment. The issue is that oTree generates a dynamic URL for each session, so I can't find the correct link. On the page where I want to navigate to the Instructions page, I'm using this code, but it's not working:

<button onclick="window.location.href='{% url 'Instructions' %}'">
    Go to Instructions
</button>

Thank you!

#2 by Chris_oTree

That is not available. I recommend putting the instructions on the same page and display them with a popup etc. Or you can make a page at a non oTree URL such as linking to a Google doc.

#3 by BonnEconLab (edited )

I have not completely understood what the purpose of “navigating the participants to the instructions” would be.

If all you intend to do is giving participants the opportunity to have a second look at the instructions, I would suggest that you outsource the text of your instructions to a separate file, say, InstructionsText.html. You can then include InstructiontsText.html in your templates via

{{ include_sibling 'InstructionsText.html' }}

See https://otree.readthedocs.io/en/latest/templates.html#includable-templates.

In subsequent pages, you can embed the {{ include_sibling 'InstructionsText.html' }} in a collapsible or in a modal. I am attaching two screenshots plus a ZIP file with code showcasing the two variants.

#4 by Paw

Hi!

Thanks for your great answers! I tested it, and it worked properly when the instructions display static text as in your example. However, the issue arises when there are embedded variables from oTree pages into the HTML template (e.g., 'There are {{ totalPlayers }} participants in this study. In each of the next {{ numRounds }} rounds, etc.').

#5 by BonnEconLab

@Paw wrote:

> However, the issue arises when there are embedded variables from oTree pages into the HTML template (e.g., 'There are {{ totalPlayers }} participants in this study. In each of the next {{ numRounds }} rounds, etc.').

This shouldn’t be a problem. You need to include the respective variables in the `vars_for_template` of the “outer” page into which you want InstructionsText.html to be included.

Please find example code attached. It combines variables that are common across all those pages into which you include InstructionsText.html with variables that are local to each including page:


########################
##  From __init__.py  ##
########################


def common_dict(player):

    return dict(
        totalPlayers=10,
        numRounds=5,
        whoAmI=player.id_in_group,
    )


class Instructions(Page):

    @staticmethod
    def vars_for_template(player):
        common_vars = common_dict(player)
        local_vars = dict(
            local_variable_I="This text is a <strong>local</strong> string for <i>Instructions.html</i>.",
        )
        return {**common_vars, **local_vars}


class InstructionsIncludedAsACard(Page):

    @staticmethod
    def vars_for_template(player):
        common_vars = common_dict(player)
        local_vars = dict(
            local_variable_II="This text is a <strong>local</strong> string for <i>InstructionsIncludedAsACard.html</i>.",
        )
        return {**common_vars, **local_vars}


class InstructionsIncludedAsAModal(Page):

    @staticmethod
    def vars_for_template(player):
        common_vars = common_dict(player)
        local_vars = dict(
            local_variable_III="This text is a <strong>local</strong> string for <i>InstructionsIncludedAsAModal.html</i>.",
        )
        return {**common_vars, **local_vars}

#6 by Paw

Thanks so much! It's perfectly working now!!

Write a reply

Set forum username