possible to use nested if in html?

936 views
Skip to first unread message

manit

unread,
Nov 10, 2021, 5:24:44 PM11/10/21
to oTree help & discussion
Hello,

I'm using if statement within an if nested, but it's not working, and I'm assuming it has to do with the syntax.

I have different texts to display for 3 scenarios, but the texts for two scenarios (the first highlight) are similar, with just small differences, so I lump them together, with some if statements. (these sub-"ifs" are in blue and green). But there's an error message about the placement of endif. I don't really see a way to indicate the nested ness as indentation doesn't seem to really work here...



            {% if player.contribution_dp == 5 or if player.contribution_dp == 10 %}
General text for all
<br>
    <hr>
        {% if player.contribution_dp == 5 %}

Text for cont = 5 
        {% elif player.contribution_dp == 10 %}
Text for cont = 10
        {% endif %}
<hr>
you will receive

    {% if player.contribution_dp == 5 %}
§{{player.B_r1_c5_sent}}.

    {% elif player.contribution_dp == 10 %}
§{{player.B_r1_c10_sent}}.

    {% endif %}
</p>

{% elif player.contribution_dp == 0 %}
<p>
You sent 0 to the other participant.
    <br>
<hr>


    {% endif %}
<br>
    {% next_button %}


{% endblock %}

Jonas

unread,
Nov 15, 2021, 12:43:05 PM11/15/21
to oTree help & discussion
There is no need to do anything special to nest if statements in HTML. I can't spot the issue in the code. Can you provide the error message?
Reply all
Reply to author
Forward
0 new messages